KVStore

Trait KVStore 

Source
pub trait KVStore<K: U64 = u64, V: Serialize + DeserializeOwned + Clone = Properties>: Clone {
    // Required methods
    fn new(name: Option<&str>) -> Self;
    fn len(&self) -> u64;
    fn is_empty(&self) -> bool;
    fn get(&self, key: K) -> Option<&V>;
    fn get_mut(&mut self, key: K) -> Option<&mut V>;
    fn set(&mut self, key: K, value: V);
    fn has(&self, key: K) -> bool;
    fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)>
       where K: 'a,
             V: 'a;
    fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = (&'a K, &'a mut V)>
       where K: 'a,
             V: 'a;

    // Provided method
    fn cleanup(&mut self) { ... }
}
Expand description

Represents a key-value store

Required Methods§

Source

fn new(name: Option<&str>) -> Self

New key-value store

Source

fn len(&self) -> u64

The length of the store

Source

fn is_empty(&self) -> bool

Check if the store is empty

Source

fn get(&self, key: K) -> Option<&V>

Get a value from the store

Source

fn get_mut(&mut self, key: K) -> Option<&mut V>

Get a mutable value from the store

Source

fn set(&mut self, key: K, value: V)

Set a value in the store

Source

fn has(&self, key: K) -> bool

Check if a key exists

Source

fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a V)>
where K: 'a, V: 'a,

Iterate over the store

Source

fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = (&'a K, &'a mut V)>
where K: 'a, V: 'a,

Iterate mutably over the store

Provided Methods§

Source

fn cleanup(&mut self)

Cleanup the store

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<K: U64, V: Serialize + DeserializeOwned + Clone> KVStore<K, V> for FileKV<K, V>

Available on crate feature std only.
Source§

impl<K: U64, V: Serialize + DeserializeOwned + Clone> KVStore<K, V> for KV<K, V>