Expand description
§stupid-simple-kv
A dead-simple, pluggable, and binary-sorted key-value store for Rust.
§Features
- Order-preserving tuple-style keys: Compose keys using
u64,i64,bool,String, tuples, or your own struct if it implementsIntoKey. - Pluggable design: Swap between memory or SQLite backends, or define your own by implementing
KvBackend. - Automatic value serialization: Store any serde-serializable value as a
KvValue. - List/query API: Filter or range-scan with
KvListBuilder. - Easy JSON import/export: Dump or restore the store’s contents for debugging or migration.
- Typed errors and strict Rust interface.
§Quickstart
use stupid_simple_kv::{Kv, MemoryBackend, KvValue, IntoKey};
let backend = Box::new(MemoryBackend::new());
let mut kv = Kv::new(backend);
let key = (42u64, true, -17i64, "foo").to_key();
kv.set(&key, "value".into()).unwrap();
assert_eq!(kv.get(&key).unwrap(), Some("value".into()));
kv.delete(&key).unwrap();§Listing and Filtering
use stupid_simple_kv::{Kv, MemoryBackend, KvValue, IntoKey};
let backend = Box::new(MemoryBackend::new());
let mut kv = Kv::new(backend);
for i in 0..5 as i64 {
let key = (1u64, i, true).to_key();
kv.set(&key, i.into()).unwrap();
}
// Fetch all records with prefix (1, _, true)
let items = kv.list().prefix(&(1u64,)).entries().unwrap();
assert!(items.len() >= 1);§Implementing a Backend
For custom persistence, implement KvBackend. See backends/mod.rs or the SQLite backend for real examples.
§Value Types
All values are stored as KvValue (enum, supports u64, i64, f64, string, bool, null, arrays, objects, binary data).
§JSON Import/Export
use stupid_simple_kv::{Kv, MemoryBackend, KvValue, IntoKey};
let mut kv = Kv::new(Box::new(MemoryBackend::new()));
let json = kv.dump_json().unwrap();
let mut loaded = Kv::from_json_string(Box::new(MemoryBackend::new()), json).unwrap();Modules§
Structs§
- Kv
- Main key-value store abstraction.
- KvKey
- Key type for stupid-simple-kv. Must be order-preserving (lexicographically).
- KvList
Builder - Builder for flexible queries over a key/value backend.
- Memory
Backend - Sqlite
Backend
Enums§
Traits§
- IntoKey
- Trait to convert any Rust type or tuple into a key suitable for [
Kv] operations. - KvBackend
- Trait for all key-value store backends.