Struct Storage

Source
pub struct Storage<K, V> { /* private fields */ }
Expand description

A thread-safe key-value storage using DashMap.

§Examples

use kvdb_lib::Storage;

let storage = Storage::new(); storage.set(1, “value1”);

assert_eq!(storage.get(&1), Some(“value1”));

Implementations§

Source§

impl<K, V> Storage<K, V>
where K: Eq + Hash + Clone + Copy, V: Clone + Copy,

Source

pub fn new() -> Self

Creates a new, empty Storage.

§Examples

use kvdb_lib::Storage;

let storage: Storage<i32, &str> = Storage::new();

Source

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

Inserts a key-value pair into the storage.

If the storage did not have this key present, None is returned. If the storage did have this key present, the value is updated, and the old value is returned.

§Examples

use kvdb_lib::Storage;

let storage = Storage::new(); storage.set(1, “value1”);

assert_eq!(storage.get(&1), Some(“value1”));

Source

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

Retrieves a value from the storage, given a key.

§Examples

use kvdb_lib::Storage;

let storage = Storage::new(); storage.set(1, “value1”);

assert_eq!(storage.get(&1), Some(“value1”));

Source

pub fn get_all(&self) -> Vec<(K, V)>

Retrieves all key-value pairs from the storage as a vector of tuples.

§Examples

use kvdb_lib::Storage;

let storage = Storage::new();

storage.set(1, “value1”); storage.set(2, “value2”); let all = storage.get_all();

assert_eq!(all.len(), 2); assert!(all.contains(&(1, “value1”))); assert!(all.contains(&(2, “value2”)));

Source

pub fn remove(&self, key: K)

Removes a key-value pair from the storage.

§Examples

use kvdb_lib::Storage;

let storage = Storage::new();

storage.set(1, “value1”); storage.remove(1);

assert_eq!(storage.get(&1), None);

Auto Trait Implementations§

§

impl<K, V> Freeze for Storage<K, V>

§

impl<K, V> !RefUnwindSafe for Storage<K, V>

§

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

§

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

§

impl<K, V> Unpin for Storage<K, V>

§

impl<K, V> !UnwindSafe for Storage<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.