Skip to content

semtexzv/stor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stor

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.

Features

  • Typed tablesTyped<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 / Transaction design, with RocksDB as the default backend

Usage

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(())
})?;

Serialization formats

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.

Design

The core abstraction is trait-based:

  • Store — opens tables, creates transactions
  • Table — get/put/delete/range operations, parameterized by key and value codecs
  • Transaction — read or write scope with commit semantics
  • EFormat / 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.

License

MIT

About

Simple embedded structured storage

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages