pub enum Entry {
Vacant(VacantEntry),
Occupied(OccupiedEntry),
}
Expand description
Represents a single entry in the tree, which may or may not exist.
Variants§
Vacant(VacantEntry)
Represents a missing entry in the tree
Occupied(OccupiedEntry)
Represents an existing entry in the tree
Implementations§
source§impl Entry
impl Entry
sourcepub fn key(&self) -> Arc<[u8]>
pub fn key(&self) -> Arc<[u8]>
Returns a reference to this entry’s key
Examples
use lsm_tree::{Config, Tree};
let tree = Tree::open(Config::new(folder))?;
let entry = tree.entry("a")?;
assert_eq!("a".as_bytes(), &*entry.key());
sourcepub fn and_update<V: AsRef<[u8]>, F: FnOnce(&Arc<[u8]>) -> V>(
self,
f: F
) -> Result<Self>
pub fn and_update<V: AsRef<[u8]>, F: FnOnce(&Arc<[u8]>) -> V>( self, f: F ) -> Result<Self>
Updates the value if it exists before any potential inserts.
Examples
use lsm_tree::{Config, Tree};
let tree = Tree::open(Config::new(folder))?;
let value = tree.entry("a")?.or_insert("abc")?;
assert_eq!("abc".as_bytes(), &*value);
let value = tree.entry("a")?.and_update(|_| "def")?.or_insert("abc")?;
assert_eq!("def".as_bytes(), &*value);
Errors
Will return Err
if an IO error occurs.
sourcepub fn or_insert<V: AsRef<[u8]>>(&self, value: V) -> Result<Arc<[u8]>>
pub fn or_insert<V: AsRef<[u8]>>(&self, value: V) -> Result<Arc<[u8]>>
Ensures a value is in the entry by inserting the default if empty, and returns that value.
Examples
use lsm_tree::{Config, Tree};
let tree = Tree::open(Config::new(folder))?;
let value = tree.entry("a")?.or_insert("abc")?;
assert_eq!("abc".as_bytes(), &*value);
Errors
Will return Err
if an IO error occurs.
sourcepub fn or_insert_with<V: AsRef<[u8]>, F: FnOnce() -> V>(
&self,
f: F
) -> Result<Arc<[u8]>>
pub fn or_insert_with<V: AsRef<[u8]>, F: FnOnce() -> V>( &self, f: F ) -> Result<Arc<[u8]>>
Ensures a value is in the entry by inserting the result of the default function if empty, and returns that value.
Examples
use lsm_tree::{Config, Tree};
let tree = Tree::open(Config::new(folder))?;
let value = tree.entry("a")?.or_insert_with(|| "abc")?;
assert_eq!("abc".as_bytes(), &*value);
Errors
Will return Err
if an IO error occurs.
sourcepub fn or_insert_with_key<V: AsRef<[u8]>, F: FnOnce(&Arc<[u8]>) -> V>(
&self,
f: F
) -> Result<Arc<[u8]>>
pub fn or_insert_with_key<V: AsRef<[u8]>, F: FnOnce(&Arc<[u8]>) -> V>( &self, f: F ) -> Result<Arc<[u8]>>
Ensures a value is in the entry by inserting the result of the default function if empty, and returns that value.
Examples
use lsm_tree::{Config, Tree};
let tree = Tree::open(Config::new(folder))?;
let value = tree.entry("a")?.or_insert_with_key(|k| k.clone())?;
assert_eq!("a".as_bytes(), &*value);
Errors
Will return Err
if an IO error occurs.
Auto Trait Implementations§
impl !RefUnwindSafe for Entry
impl Send for Entry
impl Sync for Entry
impl Unpin for Entry
impl !UnwindSafe for Entry
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