add Vector::clear
This commit is contained in:
parent
cb908c8198
commit
3e37286621
@ -32,10 +32,17 @@ impl Default for Str {
|
||||
}
|
||||
|
||||
impl Str {
|
||||
#[must_use]
|
||||
pub fn clear<R>(self, transaction: &mut TransactionHandle<R>) -> Self {
|
||||
Self(self.0.clear(transaction))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn set<R>(self, transaction: &mut TransactionHandle<R>, 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()
|
||||
}
|
||||
|
@ -34,9 +34,19 @@ impl Default for Vector {
|
||||
}
|
||||
|
||||
impl Vector {
|
||||
#[must_use]
|
||||
pub fn clear<R>(self, transaction: &mut TransactionHandle<R>) -> Self {
|
||||
if !self.data.start.is_null() {
|
||||
transaction.free_range(self.data);
|
||||
}
|
||||
|
||||
Self::new()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn set<R>(self, transaction: &mut TransactionHandle<R>, 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] {
|
||||
|
Loading…
Reference in New Issue
Block a user