Typed embedded key-value storage for Rust, built on RocksDB.
stor provides a thin, type-safe abstraction over key-value stores. You define your key and value types once, and the library handles serialization, deserialization, and zero-copy access where possible.
- Typed tables —
Typed<Store, KeyCodec, ValueCodec>gives you compile-time guarantees that keys and values match - Pluggable serialization — JSON, Postcard, Protokit, Ordcode, or raw bytes via zerocopy
- Transactions — read and write transactions with RAII commit semantics
- Range queries — forward and reverse iteration over key ranges
- Zero-copy where possible — unaligned types are read directly from the backing store without allocation
- Backend-agnostic — trait-based
Store/Table/Transactiondesign, with RocksDB as the default backend
let db = Rocks::open("./my-db")?;
let users: Typed<_, Str, SerdeJson<User>> = db.typed("users", &Default::default())?;
writetx(&db, |tx| {
users.put(tx, "alice", &User { name: "Alice", age: 30 })?;
users.put(tx, "bob", &User { name: "Bob", age: 25 })?;
Ok(())
})?;
readtx(&db, |tx| {
let alice = users.get(tx, "alice")?; // Option<User>
let all = users.range(tx, "a"..="z")?; // Iterator<(String, User)>
Ok(())
})?;Enable via Cargo features:
| Feature | Format | Use case |
|---|---|---|
format-json |
serde_json | Human-readable, debugging |
format-postcard |
postcard | Compact binary, no_std friendly |
format-protokit |
protokit | Protocol Buffers |
format-ordcode |
ordcode | Order-preserving keys for range scans |
Raw types via zerocopy (OwnedType, UnalignedType, OwnedSlice) are always available for maximum performance.
The core abstraction is trait-based:
Store— opens tables, creates transactionsTable— get/put/delete/range operations, parameterized by key and value codecsTransaction— read or write scope with commit semanticsEFormat/DFormat— encode and decode traits for keys and values
This means stor could support backends other than RocksDB (LMDB, SQLite, in-memory) by implementing the Store trait.
MIT