[][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 std::path::Path;
use heed::{EnvOpenOptions, Database};
use heed::types::*;

fs::create_dir_all(Path::new("target").join("zerocopy.mdb"))?;
let env = EnvOpenOptions::new().open(Path::new("target").join("zerocopy.mdb"))?;

// we will open the default unamed database
let db: Database<Str, OwnedType<i32>> = env.create_database(None)?;

// opening a write transaction
let mut wtxn = env.write_txn()?;
db.put(&mut wtxn, "seven", &7)?;
db.put(&mut wtxn, "zero", &0)?;
db.put(&mut wtxn, "five", &5)?;
db.put(&mut wtxn, "three", &3)?;
wtxn.commit()?;

// opening a read transaction
// to check if those values are now available
let mut rtxn = env.read_txn()?;

let ret = db.get(&rtxn, "zero")?;
assert_eq!(ret, Some(0));

let ret = db.get(&rtxn, "five")?;
assert_eq!(ret, Some(5));

Re-exports

pub use byteorder;
pub use heed_types as types;
pub use zerocopy;

Modules

flags

Structs

Database

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

Env
EnvClosingEvent
EnvOpenOptions
Lazy

Owns bytes that can be decoded on demand.

LazyDecode

Lazily decode the data bytes, it can be used to avoid CPU intensive decoding before making sure we really need to decode it (e.g. based on the key).

PolyDatabase

A polymorphic database that accepts types on call methods and not at creation.

RoIter
RoPrefix
RoRange
RoRevIter
RoRevPrefix
RoRevRange
RoTxn
RwIter
RwPrefix
RwRange
RwRevIter
RwRevPrefix
RwRevRange
RwTxn

Enums

CompactionOption
Error

An error that encapsulates all possible errors in this crate.

MdbError

An LMDB error kind.

Traits

BytesDecode
BytesEncode

Functions

env_closing_event

Returns a struct that allows to wait for the effective closing of an environment.

Type Definitions

Result