Files
sal-modular/kvstore/src/traits.rs
Sameh Abouelsaad cea2d7e655 feat: Refactor kvstore and vault to use features and logging
- Remove hardcoded dependencies in kvstore Cargo.toml; use features
  instead. This allows for more flexible compilation for different
  targets (native vs. WASM).
- Improve logging in vault crate using the `log` crate. This makes
  debugging easier and provides more informative output during
  execution.  Native tests use `env_logger`, WASM tests use
  `console_log`.
- Update README to reflect new logging best practices.
- Add cfg attributes to native and wasm modules to improve clarity.
- Update traits.rs to specify Send + Sync behavior expectations.
2025-05-15 16:42:19 +03:00

32 lines
1.2 KiB
Rust

//! Async trait for key-value storage
use crate::error::Result;
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
/// Async key-value store interface.
///
/// For native (non-wasm32) backends, implementers should be `Send + Sync` to support runtime-agnostic async usage.
/// For WASM (wasm32) backends, `Send + Sync` is not required and types may not implement them.
///
/// Methods:
/// - get
/// - set
/// - remove (was delete)
/// - contains_key (was exists)
/// - keys
/// - clear
/// Async key-value store interface for both native and WASM backends.
///
/// For native (non-wasm32) backends, implementers should be `Send + Sync` to support async usage.
/// For WASM (wasm32) backends, `Send + Sync` is not required.
#[async_trait::async_trait]
pub trait KVStore {
async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
async fn set(&self, key: &str, value: &[u8]) -> Result<()>;
async fn remove(&self, key: &str) -> Result<()>;
async fn contains_key(&self, key: &str) -> Result<bool>;
async fn keys(&self) -> Result<Vec<String>>;
async fn clear(&self) -> Result<()>;
}