Expand description
§TinyKV
A minimal JSON-based persistent key-value store for Rust projects.
Supports optional TTL (expiration), auto-saving, backup, and serialization via serde
or nanoserde
.
Works in no_std
environments with alloc
.
§Features
- File-based storage using pretty-formatted JSON
- Optional TTL expiration support per key
- Auto-saving changes on modification
- Backup support with
.bak
files - Simple interface with
serde
(default) ornanoserde
(feature flag) no_std
support withalloc
§Feature Flags
default
: Usesserde
for serialization (maximum compatibility) andstd
nanoserde
: Usesnanoserde
for minimal binary size and faster compilationstd
: Enablesstd
library (enabled by default)
§Example
use tinykv::TinyKV;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut kv = TinyKV::open("mydata.json")?.with_auto_save();
kv.set("username", "hasan".to_string())?;
kv.set_with_ttl("session_token", "abc123".to_string(), 60)?; // 60 seconds TTL
let user: Option<String> = kv.get("username")?;
println!("User: {:?}", user);
Ok(())
}
Structs§
- TinyKV
- A simple persistent key-value store with TTL and auto-save.
Enums§
- TinyKV
Error - Errors that can occur while using the TinyKV store.