diff --git a/src/datastructures/string.rs b/src/datastructures/string.rs index 6881442..0f8d1c7 100644 --- a/src/datastructures/string.rs +++ b/src/datastructures/string.rs @@ -32,10 +32,17 @@ impl Default for Str { } impl Str { + #[must_use] + pub fn clear(self, transaction: &mut TransactionHandle) -> Self { + Self(self.0.clear(transaction)) + } + + #[must_use] pub fn set(self, transaction: &mut TransactionHandle, s: &str) -> Self { Self(self.0.set(transaction, s.as_bytes())) } + #[must_use] pub fn get(self, reader: &impl ReaderTrait) -> &str { std::str::from_utf8(self.0.get(reader)).unwrap() } diff --git a/src/datastructures/vector.rs b/src/datastructures/vector.rs index 01f69e5..e4e34a1 100644 --- a/src/datastructures/vector.rs +++ b/src/datastructures/vector.rs @@ -34,9 +34,19 @@ impl Default for Vector { } impl Vector { + #[must_use] + pub fn clear(self, transaction: &mut TransactionHandle) -> Self { + if !self.data.start.is_null() { + transaction.free_range(self.data); + } + + Self::new() + } + + #[must_use] pub fn set(self, transaction: &mut TransactionHandle, s: &[u8]) -> Self { let data = if s.is_empty() { - Vector::new().data + Self::new().data } else { let (range, data) = transaction.allocate_range(s.len() as u64); data.copy_from_slice(s.as_bytes()); @@ -47,7 +57,7 @@ impl Vector { transaction.free_range(self.data); } - Vector { data } + Self { data } } pub fn get(self, reader: &impl ReaderTrait) -> &[u8] {