use std::sync::Arc;
use async_trait::async_trait;
use crate::PlatformError;
pub enum KvOp {
Set { key: String, value: Vec<u8> },
Delete { key: String },
}
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
pub trait KvStore: Send + Sync {
async fn get(&self, key: &str) -> Result<Option<Vec<u8>>, PlatformError>;
async fn set(&self, key: &str, value: &[u8]) -> Result<(), PlatformError>;
async fn delete(&self, key: &str) -> Result<bool, PlatformError>;
async fn list_keys(&self, prefix: Option<&str>) -> Result<Vec<String>, PlatformError>;
async fn batch(&self, ops: Vec<KvOp>) -> Result<(), PlatformError>;
}
pub trait KvStoreClone: KvStore {
fn clone_box(&self) -> Arc<dyn KvStore>;
}