Skip to main content

KvStore

Trait KvStore 

Source
pub trait KvStore: Send + Sync {
    // Required methods
    fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
    fn put(&self, key: &str, value: &[u8]) -> Result<()>;
    fn delete(&self, key: &str) -> Result<bool>;
}
Expand description

Generic byte-oriented key-value store.

Sync by design — SQLite is synchronous, and local-disk calls inside an async context are acceptable. The trait is object-safe, so a cache or session store can hold a Box<dyn KvStore> / Arc<dyn KvStore>.

Required Methods§

Source

fn get(&self, key: &str) -> Result<Option<Vec<u8>>>

Fetch the value for key, or None if it is absent.

Source

fn put(&self, key: &str, value: &[u8]) -> Result<()>

Store value under key, replacing any existing value.

Source

fn delete(&self, key: &str) -> Result<bool>

Remove key. Returns true if a value was present.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§