- Added basic project structure with workspace and crates: `kvstore`, `vault`, `evm_client`, `cli_app`, `web_app`. - Created initial `Cargo.toml` files for each crate. - Added placeholder implementations for key components. - Included initial documentation files (`README.md`, architecture docs, repo structure). - Included initial implementaion for kvstore crate(async API, backend abstraction, separation of concerns, WASM/native support, testability) - Included native and browser tests for the kvstore crate
53 lines
1.4 KiB
Markdown
53 lines
1.4 KiB
Markdown
# kvstore: Async Key-Value Store for Native and WASM
|
|
|
|
`kvstore` provides a runtime-agnostic, async trait for key-value storage, with robust implementations for both native (using `sled`) and browser/WASM (using IndexedDB via the `idb` crate) environments.
|
|
|
|
## Features
|
|
- **Unified async trait**: Same API for all platforms. Methods: `get`, `set`, `remove`, `contains_key`, `keys`, `clear`.
|
|
- **Native backend**: Uses `sled` for fast, embedded storage. Blocking I/O is offloaded with `tokio::task::spawn_blocking`.
|
|
- **WASM backend**: Uses IndexedDB via the `idb` crate for browser storage. Fully async and Promise-based.
|
|
- **Error handling**: Consistent error types across platforms.
|
|
- **Conditional compilation**: Uses Cargo features and `cfg` to select the backend.
|
|
|
|
## Usage
|
|
|
|
Add to your `Cargo.toml`:
|
|
```toml
|
|
[dependencies]
|
|
kvstore = { path = "../kvstore" }
|
|
```
|
|
|
|
### Example
|
|
```rust
|
|
use kvstore::{KVStore, NativeStore};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let store = NativeStore::open("/tmp/mydb").unwrap();
|
|
store.set("foo", b"bar").await.unwrap();
|
|
let val = store.get("foo").await.unwrap();
|
|
println!("Got: {:?}", val);
|
|
}
|
|
```
|
|
|
|
For WASM/browser, use `WasmStore` and run in a browser environment.
|
|
|
|
## Testing
|
|
|
|
### Native
|
|
```sh
|
|
cargo test -p kvstore --features native
|
|
```
|
|
|
|
### WASM (browser)
|
|
```sh
|
|
cd kvstore
|
|
wasm-pack test --headless --firefox --features web
|
|
```
|
|
|
|
## Architecture
|
|
- See `../docs/Architecture.md` for full design details.
|
|
|
|
## License
|
|
MIT OR Apache-2.0
|