Skip to main content

rings_core/storage/
mod.rs

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