Skip to main content

rings_core/storage/
mod.rs

1//! Module of MemStorage and PersistenceStorage
2
3#[cfg(feature = "wasm")]
4pub mod idb;
5pub mod memory;
6#[cfg(all(not(feature = "wasm"), not(feature = "dummy")))]
7pub mod sled;
8
9use async_trait::async_trait;
10
11use crate::error::Result;
12pub use crate::storage::memory::MemStorage;
13
14/// Key value storage interface
15#[cfg_attr(feature = "wasm", async_trait(?Send))]
16#[cfg_attr(not(feature = "wasm"), async_trait)]
17pub trait KvStorageInterface<V> {
18    /// Get a cache entry by `key`.
19    async fn get(&self, key: &str) -> Result<Option<V>>;
20
21    /// Put `entry` in the cache under `key`.
22    async fn put(&self, key: &str, value: &V) -> Result<()>;
23
24    async fn get_all(&self) -> Result<Vec<(String, V)>>;
25
26    /// Remove an `entry` by `key`.
27    async fn remove(&self, key: &str) -> Result<()>;
28
29    /// Delete all values.
30    async fn clear(&self) -> Result<()>;
31
32    /// Get the current storage usage.
33    async fn count(&self) -> Result<u32>;
34}