pub struct ConstMapShard<'a, K: Key + Send + Sync + Hash + Eq, const V: usize, H: WriteHook<K> = NoHook, D: Durability = Bitcask> { /* private fields */ }Expand description
Handle for atomic multi-key operations within a single shard.
Obtained via ConstMap::atomic. The shard + index locks are held for the
lifetime of this struct — keep the closure short.
Implementations§
Source§impl<K: Key + Send + Sync + Hash + Eq, const V: usize, H: WriteHook<K>, D: Durability> ConstMapShard<'_, K, V, H, D>
impl<K: Key + Send + Sync + Hash + Eq, const V: usize, H: WriteHook<K>, D: Durability> ConstMapShard<'_, K, V, H, D>
pub fn put(&mut self, key: &K, value: &[u8; V]) -> DbResult<Option<[u8; V]>>
pub fn insert(&mut self, key: &K, value: &[u8; V]) -> DbResult<()>
pub fn delete(&mut self, key: &K) -> DbResult<Option<[u8; V]>>
Sourcepub fn update(
&mut self,
key: &K,
f: impl FnOnce(&[u8; V]) -> [u8; V],
) -> DbResult<Option<[u8; V]>>
pub fn update( &mut self, key: &K, f: impl FnOnce(&[u8; V]) -> [u8; V], ) -> DbResult<Option<[u8; V]>>
Read-modify-write within this shard: applies f to the current value and
stores the result. Returns Some(new_value) if the key existed, None
otherwise (closure not invoked). The closure must not be heavy — the shard
- index locks are held.
Sourcepub fn fetch_update(
&mut self,
key: &K,
f: impl FnOnce(&[u8; V]) -> [u8; V],
) -> DbResult<Option<[u8; V]>>
pub fn fetch_update( &mut self, key: &K, f: impl FnOnce(&[u8; V]) -> [u8; V], ) -> DbResult<Option<[u8; V]>>
Like update(), but returns Some(old_value) instead of
the new one.
Sourcepub fn upsert<U: IntoUpsert<[u8; V]>>(
&mut self,
key: &K,
f: impl FnOnce(Option<&[u8; V]>) -> U,
) -> DbResult<U::Out>
pub fn upsert<U: IntoUpsert<[u8; V]>>( &mut self, key: &K, f: impl FnOnce(Option<&[u8; V]>) -> U, ) -> DbResult<U::Out>
Decide-and-write within this shard. The closure must be short — shard lock is held.
pub fn try_get(&self, key: &K) -> DbResult<Option<[u8; V]>>
pub fn get_or_err(&self, key: &K) -> DbResult<[u8; V]>
pub fn try_contains(&self, key: &K) -> DbResult<bool>
Auto Trait Implementations§
impl<'a, K, const V: usize, H = NoHook, D = Bitcask> !RefUnwindSafe for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H = NoHook, D = Bitcask> !Send for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H = NoHook, D = Bitcask> !UnwindSafe for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H, D> Freeze for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H, D> Sync for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H, D> Unpin for ConstMapShard<'a, K, V, H, D>
impl<'a, K, const V: usize, H, D> UnsafeUnpin for ConstMapShard<'a, K, V, H, D>
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
Mutably borrows from an owned value. Read more