Skip to content

andrew-d/tinycdb-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinycdb-rs

Build Status Coverage Status Docs

This project consists of Rust bindings to tinycdb, a small library for creating and reading constant key-value databases.

Example

Add this to your Cargo.toml:

[dependencies.tinycdb]

git = "https://github.com/andrew-d/tinycdb-rs"

Then, in your crate:

extern crate tinycdb;

use tinycdb::base::Cdb;

Reading a database:

let path = Path::new("test.cdb");

let mut db = match Cdb::open(&path) {
    Ok(db) => db,
    Err(why) => panic!("Could not open CDB: {}", why),
};

match db.find(b"foo") {
    Some(val) => println!("Value of 'foo' key is: {}", val),
    None      => println!("'foo' key was not found"),
};

Creating a database:

let path = Path::new("created.cdb");

let res = Cdb::new(&path, |creator| {
    let r = creator.add(b"foo", b"bar");
    assert!(r.is_ok());
});

let mut db = match res {
    Ok(db)   => db,
    Err(why) => panic!("Could not create database: {}", why),
};

// Now, use 'db' as normal...

License

MIT (the original code of TinyCDB is in the public domain)

About

Bindings to TinyCDB for Rust.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •