Crate rustbreak [] [src]

Rustbreak

Rustbreak is a Daybreak inspiried single file Database. It uses bincode or yaml to compactly save data. It is thread safe and very fast due to staying in memory until flushed to disk.

It can be used for short-lived processes or with long-lived ones:

use rustbreak::{Database, Result};

fn get_data(key: &str) -> Result<String> {
    let db = try!(Database::<String>::open("/tmp/database"));
    db.retrieve(key)
}
use rustbreak::{Database, Result};

lazy_static! {
    static ref DB: Database<String> = {
        Database::open("/tmp/more_data").unwrap()
    };
}

fn get_data(key: &str) -> Result<u64> {
    DB.retrieve(key)
}

fn set_data(key: &str, d: u64) -> Result<()> {
    let mut lock = try!(DB.lock());
    let old_data : u64 = try!(lock.retrieve(key));
    lock.insert(key, d + old_data)
}

Structs

Database

The Database structure

Lock

Structure representing a lock of the Database

Transaction

A Transaction that is atomic in writes

TransactionLock

A TransactionLock that is atomic in writes and defensive

Enums

BreakError

The Error type exported by BreakError, usually you only need to check against NotFound, however it might be useful sometimes to get other errors.

Type Definitions

Result

Alias for our Result Type