[][src]Struct tari_storage::HashmapDatabase

pub struct HashmapDatabase<K: Eq + Hash, V> { /* fields omitted */ }

The HMapDatabase mimics the behaviour of LMDBDatabase without keeping a persistent copy of the key-value records. It allows key-value pairs to be inserted, retrieved and removed in a thread-safe manner.

Implementations

impl<K: Clone + Eq + Hash, V: Clone> HashmapDatabase<K, V>[src]

pub fn new() -> Self[src]

Creates a new empty HMapDatabase with the specified name

pub fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>[src]

Inserts a key-value record into the database. Internally, insert serializes the key and value using bincode and adds the pair into HashMap guarded with a RwLock.

pub fn get(&self, key: &K) -> Result<Option<V>, KeyValStoreError>[src]

Get a value from the key-value database. The retrieved value is deserialized from bincode into V

pub fn is_empty(&self) -> Result<bool, KeyValStoreError>[src]

Returns if the key-value database is empty

pub fn len(&self) -> Result<usize, KeyValStoreError>[src]

Returns the total number of entries recorded in the key-value database.

pub fn for_each<F>(&self, f: F) -> Result<(), KeyValStoreError> where
    F: FnMut(Result<(K, V), KeyValStoreError>) -> IterationResult
[src]

Iterate over all the stored records and execute the function f for each pair in the key-value database.

pub fn contains_key(&self, key: &K) -> Result<bool, KeyValStoreError>[src]

Checks whether a record exist in the key-value database that corresponds to the provided key.

pub fn remove(&self, key: &K) -> Result<(), KeyValStoreError>[src]

Remove the record from the key-value database that corresponds with the provided key.

Trait Implementations

impl<K: Default + Eq + Hash, V: Default> Default for HashmapDatabase<K, V>[src]

impl<K: Clone + Eq + Hash, V: Clone> KeyValueStore<K, V> for HashmapDatabase<K, V>[src]

fn insert(&self, key: K, value: V) -> Result<(), KeyValStoreError>[src]

Inserts a key-value pair into the key-value database.

fn get(&self, key: &K) -> Result<Option<V>, KeyValStoreError>[src]

Get the value corresponding to the provided key from the key-value database.

fn size(&self) -> Result<usize, KeyValStoreError>[src]

Returns the total number of entries recorded in the key-value database.

fn for_each<F>(&self, f: F) -> Result<(), KeyValStoreError> where
    F: FnMut(Result<(K, V), KeyValStoreError>) -> IterationResult
[src]

Iterate over all the stored records and execute the function f for each pair in the key-value database.

fn exists(&self, key: &K) -> Result<bool, KeyValStoreError>[src]

Checks whether a record exist in the key-value database that corresponds to the provided key.

fn delete(&self, key: &K) -> Result<(), KeyValStoreError>[src]

Remove the record from the key-value database that corresponds with the provided key.

Auto Trait Implementations

impl<K, V> RefUnwindSafe for HashmapDatabase<K, V>

impl<K, V> Send for HashmapDatabase<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for HashmapDatabase<K, V> where
    K: Send + Sync,
    V: Send + Sync

impl<K, V> Unpin for HashmapDatabase<K, V> where
    K: Unpin,
    V: Unpin

impl<K, V> UnwindSafe for HashmapDatabase<K, V>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Clear for T where
    T: InitializableFromZeroed + ?Sized

impl<T> From<T> for T[src]

impl<T> InitializableFromZeroed for T where
    T: Default

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SafeBorrow<T> for T where
    T: ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,