cdb32/lib.rs
1//! This crate provides support for reading and writing
2//! [CDB](https://cr.yp.to/cdb.html) files. A CDB is a "constant
3//! database" that acts as an on-disk associative array mapping keys to
4//! values, allowing multiple values for each key. It provides for fast
5//! lookups and low overheads. A constant database has no provision for
6//! updating, only rewriting from scratch.
7//!
8//! # Examples
9//!
10//! Reading a set of records:
11//!
12//! ```
13//! # fn main() -> std::io::Result<()> {
14//! use cdb32::CDB;
15//!
16//! let cdb = CDB::open("tests/test1.cdb")?;
17//! for result in cdb.find(b"one") {
18//! println!("{:?}", result?);
19//! }
20//! # Ok(())
21//! # }
22//! ```
23//!
24//! Creating a database with safe atomic updating:
25//!
26//! ```
27//! # fn main() -> std::io::Result<()> {
28//! # let tmp_dir = tempfile::tempdir()?;
29//! # let tmp_path = tmp_dir.path();
30//! # std::env::set_current_dir(&tmp_path)?;
31//! use cdb32::CDBWriter;
32//!
33//! let mut cdb = CDBWriter::create("temporary.cdb")?;
34//! cdb.add(b"one", b"Hello, ")?;
35//! cdb.add(b"one", b"world!\n")?;
36//! cdb.add(b"two", &[1, 2, 3, 4])?;
37//! cdb.finish()?;
38//! # Ok(())
39//! # }
40//! ```
41//!
42//! # References
43//!
44//! * [D. J. Bernstein's original software](https://cr.yp.to/cdb.html)
45//! * [Constant Database (cdb) Internals](https://www.unixuser.org/~euske/doc/cdbinternals/index.html)
46//! * [Wikipedia](https://en.wikipedia.org/wiki/Cdb_(software))
47
48mod hash;
49mod reader;
50mod uint32;
51mod writer;
52
53pub use crate::reader::{CDBIter, CDBKeyValueIter, CDBValueIter, Result, CDB};
54pub use crate::writer::{CDBMake, CDBWriter};