4 stable releases
1.0.3 | Jun 21, 2020 |
---|
#181 in Database implementations
59KB
1.5K
SLoC
MHdb is a pure Rust database implementation, based on dbm.
See crate documentation.
Changelog
v1.0.3
- Update Cargo.toml
v1.0.2
- Update Cargo.toml
v1.0.1
- Update docs
v1.0.0
- Initial release
lib.rs
:
MHdb is a pure Rust embedded key-value store database, based on dbm.
Simple use
use mhdb::{Db, prelude::*};
let mut db = Db::open("mydb")?;
let key = "Number".to_owned();
let val = 42i32;
db.store(key.clone(), val)?;
let num: Option<i32> = db.fetch(42u8)?;
assert_eq!(num, Some(val));
println!("{}", num.unwrap());
Any type implementing Datum
can be stored in the database.
Datum
A datum represents a single item in the database. Types
used as keys and/or values must therefore implement the
Datum
trait.
Datum
is automatically implemented on any type implementing
the Serde traits Serialize
and Deserialize
.
In-memory database
Any type which implements the Source
trait can be used
as database sources. This trait is in turn automatically
implemented for any type which implements the Read
,
Write
, Seek
, Sync
, and Send
standard library traits.
A vector may therefore be used as an in-memory database.
use mhdb::{Db, prelude::*};
use std::io::Cursor;
let dirf = Cursor::new(Vec::<u8>::new());
let pagf = Cursor::new(Vec::<u8>::new());
let mut db: Db = Db::with_sources(Box::new(pagf), Box::new(dirf))?;
db.store(42u8, "Hello world".to_owned())?;
let txt: Option<String> = db.fetch(42u8)?;
assert!(txt.is_some());
println!("{}", txt.unwrap());
Limitations
- Key-value pairs can not be larger than 506B
Db
objects are not thread safe
Dependencies
~225KB