Struct fjall::TransactionalPartitionHandle
source · pub struct TransactionalPartitionHandle { /* private fields */ }Expand description
Access to a partition of a transactional keyspace
Implementations§
source§impl TransactionalPartitionHandle
impl TransactionalPartitionHandle
sourcepub fn take<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<UserValue>>
pub fn take<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<UserValue>>
Removes an item and returns its value if it existed.
The operation will run wrapped in a transaction.
partition.insert("a", "abc")?;
let taken = partition.take("a")?.unwrap();
assert_eq!(b"abc", &*taken);
let item = partition.get("a")?;
assert!(item.is_none());§Errors
Will return Err if an IO error occurs.
sourcepub fn fetch_update<K: AsRef<[u8]>, F: Fn(Option<&UserValue>) -> Option<UserValue>>(
&self,
key: K,
f: F,
) -> Result<Option<UserValue>>
pub fn fetch_update<K: AsRef<[u8]>, F: Fn(Option<&UserValue>) -> Option<UserValue>>( &self, key: K, f: F, ) -> Result<Option<UserValue>>
Atomically updates an item and returns the previous value.
Returning None removes the item if it existed before.
The operation will run wrapped in a transaction.
§Examples
partition.insert("a", "abc")?;
let prev = partition.fetch_update("a", |_| Some(Slice::from(*b"def")))?.unwrap();
assert_eq!(b"abc", &*prev);
let item = partition.get("a")?;
assert_eq!(Some("def".as_bytes().into()), item);partition.insert("a", "abc")?;
let prev = partition.fetch_update("a", |_| None)?.unwrap();
assert_eq!(b"abc", &*prev);
let item = partition.get("a")?;
assert!(item.is_none());§Errors
Will return Err if an IO error occurs.
sourcepub fn update_fetch<K: AsRef<[u8]>, F: Fn(Option<&UserValue>) -> Option<UserValue>>(
&self,
key: K,
f: F,
) -> Result<Option<UserValue>>
pub fn update_fetch<K: AsRef<[u8]>, F: Fn(Option<&UserValue>) -> Option<UserValue>>( &self, key: K, f: F, ) -> Result<Option<UserValue>>
Atomically updates an item and returns the new value.
Returning None removes the item if it existed before.
The operation will run wrapped in a transaction.
§Examples
partition.insert("a", "abc")?;
let updated = partition.update_fetch("a", |_| Some(Slice::from(*b"def")))?.unwrap();
assert_eq!(b"def", &*updated);
let item = partition.get("a")?;
assert_eq!(Some("def".as_bytes().into()), item);partition.insert("a", "abc")?;
let updated = partition.update_fetch("a", |_| None)?;
assert!(updated.is_none());
let item = partition.get("a")?;
assert!(item.is_none());§Errors
Will return Err if an IO error occurs.
sourcepub fn insert<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
key: K,
value: V,
) -> Result<()>
pub fn insert<K: AsRef<[u8]>, V: AsRef<[u8]>>( &self, key: K, value: V, ) -> Result<()>
Inserts a key-value pair into the partition.
Keys may be up to 65536 bytes long, values up to 2^32 bytes. Shorter keys and values result in better performance.
If the key already exists, the item will be overwritten.
The operation will run wrapped in a transaction.
§Examples
partition.insert("a", "abc")?;
assert!(!keyspace.read_tx().is_empty(&partition)?);§Errors
Will return Err if an IO error occurs.
sourcepub fn remove<K: AsRef<[u8]>>(&self, key: K) -> Result<()>
pub fn remove<K: AsRef<[u8]>>(&self, key: K) -> Result<()>
Removes an item from the partition.
The key may be up to 65536 bytes long. Shorter keys result in better performance.
The operation will run wrapped in a transaction.
§Examples
partition.insert("a", "abc")?;
assert!(!keyspace.read_tx().is_empty(&partition)?);
partition.remove("a")?;
assert!(keyspace.read_tx().is_empty(&partition)?);§Errors
Will return Err if an IO error occurs.
Trait Implementations§
source§impl Clone for TransactionalPartitionHandle
impl Clone for TransactionalPartitionHandle
source§fn clone(&self) -> TransactionalPartitionHandle
fn clone(&self) -> TransactionalPartitionHandle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl GarbageCollection for TransactionalPartitionHandle
impl GarbageCollection for TransactionalPartitionHandle
source§fn gc_scan(&self) -> Result<GcReport>
fn gc_scan(&self) -> Result<GcReport>
source§fn gc_with_space_amp_target(&self, factor: f32) -> Result<u64>
fn gc_with_space_amp_target(&self, factor: f32) -> Result<u64>
Auto Trait Implementations§
impl Freeze for TransactionalPartitionHandle
impl !RefUnwindSafe for TransactionalPartitionHandle
impl Send for TransactionalPartitionHandle
impl Sync for TransactionalPartitionHandle
impl Unpin for TransactionalPartitionHandle
impl !UnwindSafe for TransactionalPartitionHandle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)