Crate heed

source
Expand description

heed is a high-level wrapper of LMDB.

The cookbook will give you a variety of complete Rust programs to use with heed.


This crate simply facilitates the use of LMDB by providing a mechanism to store and retrieve Rust types. It abstracts away some of the complexities of the raw LMDB usage while retaining its performance characteristics. The functionality is achieved with the help of the serde library for data serialization concerns.

LMDB stands for Lightning Memory-Mapped Database, which utilizes memory-mapped files for efficient data storage and retrieval by mapping file content directly into the virtual address space. heed derives its efficiency from the underlying LMDB without imposing additional runtime costs.

§Examples

Open a database that will support some typed key/data and ensure, 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::*;

let dir = tempfile::tempdir()?;
let env = unsafe { EnvOpenOptions::new().open(dir.path())? };

// we will open the default unnamed database
let mut wtxn = env.write_txn()?;
let db: Database<Str, U32<byteorder::NativeEndian>> = env.create_database(&mut wtxn, None)?;

// opening a write transaction
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§

Modules§

  • A cookbook of examples on how to use heed. Here is the list of the different topics you can learn about:
  • The set of possible iteration methods for the different iterators.

Structs§

Enums§

Traits§

Functions§

  • Returns a struct that allows to wait for the effective closing of an environment.
  • Return the LMDB library version information.

Type Aliases§