From ed91e8690d37e194c6158ac0e8ea0be57615a8d3 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Fri, 15 Nov 2024 01:55:25 +0100 Subject: [PATCH] add size_of to TxPartition --- src/tx/partition.rs | 27 +++++++++++++++++++++++++++ src/tx/write/ssi.rs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/tx/partition.rs b/src/tx/partition.rs index de91ebf..6f10aee 100644 --- a/src/tx/partition.rs +++ b/src/tx/partition.rs @@ -341,6 +341,33 @@ impl TransactionalPartitionHandle { self.inner.get(key) } + /// Retrieves the size of an item from the partition. + /// + /// The operation will run wrapped in a read snapshot. + /// + /// # Examples + /// + /// ``` + /// # use fjall::{Config, Keyspace, PartitionCreateOptions}; + /// # + /// # let folder = tempfile::tempdir()?; + /// # let keyspace = Config::new(folder).open_transactional()?; + /// # let partition = keyspace.open_partition("default", PartitionCreateOptions::default())?; + /// partition.insert("a", "my_value")?; + /// + /// let len = partition.size_of("a")?.unwrap_or_default(); + /// assert_eq!("my_value".len() as u32, len); + /// # + /// # Ok::<(), fjall::Error>(()) + /// ``` + /// + /// # Errors + /// + /// Will return `Err` if an IO error occurs. + pub fn size_of>(&self, key: K) -> crate::Result> { + self.inner.size_of(key) + } + /// Returns `true` if the partition contains the specified key. /// /// The operation will run wrapped in a read snapshot. diff --git a/src/tx/write/ssi.rs b/src/tx/write/ssi.rs index 4f6a82a..33ea14e 100644 --- a/src/tx/write/ssi.rs +++ b/src/tx/write/ssi.rs @@ -258,7 +258,7 @@ impl WriteTransaction { Ok(res) } - /// Retrieves an item from the transaction's state. + /// Retrieves the size of an item from the transaction's state. /// /// The transaction allows reading your own writes (RYOW). ///