GithubHelp home page GithubHelp logo

roach's Introduction

roach

Docs.rs Nightly

Rust object archive: strongly-typed persistent key value storage

roach is a thin wrapper over redb which allows loading and storing strongly-typed data in a customizable fashion. It is ideal for applications which need to persistently store program state or other data in a variety of ways (such as in a serialized or compressed format). The following is a simple example of how to use roach:

use roach::*;

// Define an archive type.
struct MyArchive;

// Define a key-value pair which can be stored in the archive.
impl ArchiveType<str> for MyArchive {
    // The keys will be of type string, and will be stored simply by copying the bytes.
    type Key = str;
    // The values will be of type [u8], and will be compressed using zstd before storage.
    type Value = Zstd<[u8]>;
}

// Define another key type.
impl ArchiveType<u8> for MyArchive {
    type Key = Pod<u8>;
    type Value = [u8; 5];
}

// Create a new archive.
let archive = Archive::<MyArchive>::new(backend::InMemoryBackend::new()).unwrap();
// Begin a new atomic transaction.
let mut write_txn = archive.write().unwrap();
// Store something to the str table.
write_txn.set("henlo", &[5, 10, 15]).unwrap();
// Commit the transaction.
write_txn.commit().unwrap();

// Read the data back to verify that it was saved.
let read_txn = archive.read().unwrap();
assert_eq!(&read_txn.get("henlo").unwrap().unwrap(), &[5, 10, 15]);

Optional features

bytemuck - Enables the Pod data transform, which reads the bytes of a type directly to store them.

rmp_serde - Enables the Rmp data transform, which serializes Rust types to bytes and back.

zstd - Enables the Zstd data transform, which compresses data before it is stored.

roach's People

Contributors

douglasdwyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.