1mod file_storage;
2mod local_store;
3mod sqlite_storage;
4
5pub use file_storage::FileStorage;
6pub use local_store::LocalStore;
7pub use sqlite_storage::SqliteStorage;
8
9use async_std::sync::{Arc, Mutex};
10use async_trait::async_trait;
11use cyfs_base::BuckyError;
12
13#[async_trait]
14pub trait AsyncStorage: Send + Sync {
15 async fn set_item(&mut self, key: &str, value: String) -> Result<(), BuckyError>;
16
17 async fn get_item(&self, key: &str) -> Option<String>;
18
19 async fn remove_item(&mut self, key: &str) -> Option<()>;
20
21 async fn clear(&mut self);
22
23 async fn clear_with_prefix(&mut self, prefix: &str);
24}
25
26pub type AsyncStorageSync = Arc<Mutex<Box<dyn AsyncStorage>>>;
27
28pub fn into_async_storage_sync<T>(storage: T) -> AsyncStorageSync
29where
30 T: AsyncStorage + 'static,
31{
32 Arc::new(Mutex::new(Box::new(storage) as Box<dyn AsyncStorage>))
33}