Crate cdb

source ·
Expand description

This crate provides support for reading and writing CDB files. A CDB is a “constant database” that acts as an on-disk associative array mapping keys to values, allowing multiple values for each key. It provides for fast lookups and low overheads. A constant database has no provision for updating, only rewriting from scratch.

Examples

Reading a set of records:

let cdb = cdb::CDB::open("tests/test1.cdb").unwrap();

for result in cdb.find(b"one") {
    println!("{:?}", result.unwrap());
}

Creating a database with safe atomic updating:

fn main() -> std::io::Result<()> {
    let mut cdb = cdb::CDBWriter::create("temporary.cdb")?;
    cdb.add(b"one", b"Hello, ")?;
    cdb.add(b"one", b"world!\n")?;
    cdb.add(b"two", &[1, 2, 3, 4])?;
    cdb.finish()?;
    Ok(())
}

References

Structs

CDB file reader
Iterator over all the records in the CDB.
Base interface for making a CDB file.
Iterator over a set of records in the CDB with the same key.
A CDB file writer which handles atomic updating.

Type Definitions

Type alias for CDBValueiter
A specialized Result type for I/O operations.