[][src]Crate heed

Crate heed is a high-level wrapper of LMDB, high-level doesn't mean heavy (think about Rust).

It provides you a way to store types in LMDB without any limit and with a minimal overhead as possible, relying on the zerocopy library to avoid copying bytes when that's unnecessary and the serde library when this is unavoidable.

The Lightning Memory-Mapped Database (LMDB) directly maps files parts into main memory, combined with the zerocopy library allows us to safely zero-copy parse and serialize Rust types into LMDB.

Examples

Discern let you open a database, that will support some typed key/data and ensures, at compile time, that you'll write those types and not others.

use std::fs;
use heed::{EnvOpenOptions, Database};
use heed::types::*;

fs::create_dir_all("target/zerocopy.mdb")?;

let env = EnvOpenOptions::new()
    .map_size(10 * 1024 * 1024 * 1024) // 10GB
    .max_dbs(3000)
    .open("target/zerocopy.mdb")?;

// here we specify that the key is an i32 array and the data an str
let db: Database<OwnedType<[i32; 2]>, Str> = env.create_database(Some("str"))?;

let mut wtxn = env.write_txn()?;
db.put(&mut wtxn, &[2, 3], "what's up?")?;

let ret = db.get(&wtxn, &[2, 3])?;
assert_eq!(ret, Some("what's up?"));

wtxn.commit()?;

// Be careful, you cannot open a database while in a transaction!
// So don't forget to commit/abort it before.
let db: Database<Str, ByteSlice> = env.create_database(Some("bytes"))?;

let mut wtxn = env.write_txn()?;
db.put(&mut wtxn, "hello", &[2, 3][..])?;

let ret = db.get(&wtxn, "hello")?;
assert_eq!(ret, Some(&[2, 3][..]));

wtxn.commit()?;

Re-exports

pub use byteorder;
pub use zerocopy;

Modules

types

Types that can be used to serialize and deserialize types inside databases.

Structs

Database

A typed database that accepts only the types it was created with.

Env
EnvOpenOptions
PolyDatabase

A dynamically typed database that accepts types at call (e.g. get, put).

RoIter
RoRange
RoTxn
RwIter
RwRange
RwTxn

Enums

CompactionOption
Error

An error that encapsulates all possible errors in this crate.

LmdbError

An LMDB error kind.

Traits

BytesDecode
BytesEncode

Type Definitions

Result