use std::collections::HashMap;
pub use samod_core::StorageKey;
mod filesystem;
mod in_memory;
pub use in_memory::InMemoryStorage;
#[cfg(feature = "tokio")]
pub use filesystem::tokio::FilesystemStorage as TokioFilesystemStorage;
#[cfg(feature = "gio")]
pub use filesystem::gio::FilesystemStorage as GioFilesystemStorage;
pub trait Storage: Send + Clone + 'static {
fn load(&self, key: StorageKey) -> impl Future<Output = Option<Vec<u8>>> + Send;
fn load_range(
&self,
prefix: StorageKey,
) -> impl Future<Output = HashMap<StorageKey, Vec<u8>>> + Send;
fn put(&self, key: StorageKey, data: Vec<u8>) -> impl Future<Output = ()> + Send;
fn delete(&self, key: StorageKey) -> impl Future<Output = ()> + Send;
}
pub trait LocalStorage: Clone + 'static {
fn load(&self, key: StorageKey) -> impl Future<Output = Option<Vec<u8>>>;
fn load_range(&self, prefix: StorageKey) -> impl Future<Output = HashMap<StorageKey, Vec<u8>>>;
fn put(&self, key: StorageKey, data: Vec<u8>) -> impl Future<Output = ()>;
fn delete(&self, key: StorageKey) -> impl Future<Output = ()>;
}
impl<S: Storage> LocalStorage for S {
fn load(&self, key: StorageKey) -> impl Future<Output = Option<Vec<u8>>> {
Storage::load(self, key)
}
fn load_range(&self, prefix: StorageKey) -> impl Future<Output = HashMap<StorageKey, Vec<u8>>> {
Storage::load_range(self, prefix)
}
fn put(&self, key: StorageKey, data: Vec<u8>) -> impl Future<Output = ()> {
Storage::put(self, key, data)
}
fn delete(&self, key: StorageKey) -> impl Future<Output = ()> {
Storage::delete(self, key)
}
}