Struct sled::Tree
[−]
[src]
pub struct Tree { /* fields omitted */ }
A flash-sympathetic persistent lock-free B+ tree
Methods
impl Tree
[src]
fn new(config: Config) -> Tree
[src]
Load existing or create a new Tree
.
fn config(&self) -> &Config
[src]
Returns a ref to the current Config
in use by the system.
fn get(&self, key: &[u8]) -> Option<Vec<u8>>
[src]
Retrieve a value from the Tree
if it exists.
fn cas(
&self,
key: Vec<u8>,
old: Option<Vec<u8>>,
new: Option<Vec<u8>>
) -> Result<(), Option<Vec<u8>>>
[src]
&self,
key: Vec<u8>,
old: Option<Vec<u8>>,
new: Option<Vec<u8>>
) -> Result<(), Option<Vec<u8>>>
Compare and swap. Capable of unique creation, conditional modification, or deletion. If old is None, this will only set the value if it doesn't exist yet. If new is None, will delete the value if old is correct. If both old and new are Some, will modify the value if old is correct.
Examples
use sled::Config; let t = Config::default().tree(); // unique creation assert_eq!(t.cas(vec![1], None, Some(vec![1])), Ok(())); assert_eq!(t.cas(vec![1], None, Some(vec![1])), Err(Some(vec![1]))); // conditional modification assert_eq!(t.cas(vec![1], Some(vec![1]), Some(vec![2])), Ok(())); assert_eq!(t.cas(vec![1], Some(vec![1]), Some(vec![2])), Err(Some(vec![2]))); // conditional deletion assert_eq!(t.cas(vec![1], Some(vec![2]), None), Ok(())); assert_eq!(t.get(&*vec![1]), None);
fn set(&self, key: Vec<u8>, value: Vec<u8>)
[src]
Set a key to a new value.
fn del(&self, key: &[u8]) -> Option<Vec<u8>>
[src]
Delete a value, returning the last result if it existed.
Examples
use sled::Config; let t = Config::default().tree(); t.set(vec![1], vec![1]); assert_eq!(t.del(&*vec![1]), Some(vec![1])); assert_eq!(t.del(&*vec![1]), None);
fn scan(&self, key: &[u8]) -> TreeIter
[src]
Iterate over tuples of keys and values, starting at the provided key.
Examples
use sled::Config; let t = Config::default().tree(); t.set(vec![1], vec![10]); t.set(vec![2], vec![20]); t.set(vec![3], vec![30]); let mut iter = t.scan(&*vec![2]); assert_eq!(iter.next(), Some((vec![2], vec![20]))); assert_eq!(iter.next(), Some((vec![3], vec![30]))); assert_eq!(iter.next(), None);
fn iter(&self) -> TreeIter
[src]
Iterate over the tuples of keys and values in this tree.
Examples
use sled::Config; let t = Config::default().tree(); t.set(vec![1], vec![10]); t.set(vec![2], vec![20]); t.set(vec![3], vec![30]); let mut iter = t.iter(); assert_eq!(iter.next(), Some((vec![1], vec![10]))); assert_eq!(iter.next(), Some((vec![2], vec![20]))); assert_eq!(iter.next(), Some((vec![3], vec![30]))); assert_eq!(iter.next(), None);
Trait Implementations
impl Send for Tree
[src]
impl Sync for Tree
[src]
impl Debug for Tree
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter.