1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#[cfg(feature = "wasm")]
pub mod idb;
#[cfg(not(feature = "wasm"))]
pub mod kv;
use async_trait::async_trait;
#[cfg(feature = "wasm")]
pub use self::idb::IDBStorage;
#[cfg(not(feature = "wasm"))]
pub use self::kv::KvStorage;
use crate::err::Result;
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
pub trait PersistenceStorageReadAndWrite<K, V>: PersistenceStorageOperation {
async fn get(&self, key: &K) -> Result<V>;
async fn put(&self, key: &K, entry: &V) -> Result<()>;
async fn get_all(&self) -> Result<Vec<(K, V)>>;
}
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
pub trait PersistenceStorageRemove<K>: PersistenceStorageOperation {
async fn remove(&self, key: &K) -> Result<()>;
}
#[cfg_attr(feature = "wasm", async_trait(?Send))]
#[cfg_attr(not(feature = "wasm"), async_trait)]
pub trait PersistenceStorageOperation {
async fn clear(&self) -> Result<()>;
async fn count(&self) -> Result<u64>;
async fn max_size(&self) -> Result<usize>;
async fn total_size(&self) -> Result<usize>;
async fn prune(&self) -> Result<()>;
async fn close(self) -> Result<()>;
}