Crates.io | tinycdb |
lib.rs | tinycdb |
version | 0.0.7 |
source | src |
created_at | 2014-11-20 22:19:29.9762 |
updated_at | 2015-12-19 15:16:45.679868 |
description | Bindings to the TinyCDB C library (http://www.corpit.ru/mjt/tinycdb.html) |
homepage | |
repository | https://github.com/andrew-d/tinycdb-rs |
max_upload_size | |
id | 170 |
size | 32,088 |
This project consists of Rust bindings to tinycdb, a small library for creating and reading constant key-value databases.
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...
MIT (the original code of TinyCDB is in the public domain)