byodb_rust/
lib.rs

1//! # Build Your Own Database from Scratch (in Rust)
2//!
3//! [https://build-your-own.org/database/](https://build-your-own.org/database/),
4//! but instead of Go, use Rust. This a personal project to learn both database
5//! internals and the Rust programming language.
6//!
7//! ## Example
8//!
9//! ```rust,no_run
10//! # use byodb_rust::{DB, Result, RTxn, RWTxn};
11//! # fn main() -> Result<()> {
12//! let path = "/path/to/a/db/file";
13//! let db: DB = DB::open_or_create(path)?;
14//!
15//! // Perform reads in a read transaction.
16//! {
17//!     let r_txn: RTxn<'_, '_> = db.r_txn();
18//!     for (k, v) in r_txn.in_order_iter() {
19//!         println!("key: {k:?}, val: {v:?}");
20//!     }
21//! } // read transaction is dropped at the end of scope.
22//!
23//! // Perform reads and writes in a read-write transaction.
24//! {
25//!     let mut rw_txn: RWTxn<'_, '_> = db.rw_txn();
26//!     if rw_txn.get("some_key".as_bytes())?.is_some() {
27//!         rw_txn.update("some_key".as_bytes(), "some_new_val".as_bytes())?;
28//!     }
29//!     // If rw_txn.commit() is not called b/c there was error in any of the
30//!     // above steps, then when rw_txn is dropped, it is equivalent to doing
31//!     // rw_txn.abort().
32//!     rw_txn.commit();
33//! }
34//! # Ok(())
35//! # }
36//! ```
37mod api;
38mod core;
39pub use api::*;