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§

pub use byteorder;
pub use heed_types as types;

Modules§

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

Structs§

Database
A typed database that accepts only the types it was created with.
DatabaseFlags
LMDB database flags (see http://www.lmdb.tech/doc/group__mdb__dbi__open.html for more details).
DatabaseOpenOptions
Options and flags which can be used to configure how a Database is opened.
DatabaseStat
Statistics for a database in the environment.
Env
An environment handle constructed by using EnvOpenOptions.
EnvClosingEvent
A structure that can be used to wait for the closing event. Multiple threads can wait on this event.
EnvFlags
LMDB environment flags (see http://www.lmdb.tech/doc/group__mdb__env.html for more details).
EnvInfo
Contains information about the environment.
EnvOpenOptions
Options and flags which can be used to configure how an environment is opened.
LmdbVersion
The underlying LMDB library version information.
PutFlags
LMDB put flags (see http://www.lmdb.tech/doc/group__mdb.html#ga4fa8573d9236d54687c61827ebf8cac0 or http://www.lmdb.tech/doc/group__mdb.html#ga1f83ccb40011837ff37cc32be01ad91e for more details).
ReservedSpace
A structure that is used to improve the write speed in LMDB.
RoIter
A read-only iterator structure.
RoPrefix
A read-only prefix iterator structure.
RoRange
A read-only range iterator structure.
RoRevIter
A reverse read-only iterator structure.
RoRevPrefix
A reverse read-only prefix iterator structure.
RoRevRange
A reverse read-only range iterator structure.
RoTxn
A read-only transaction.
RwIter
A read-write iterator structure.
RwPrefix
A read-write prefix iterator structure.
RwRange
A read-write range iterator structure.
RwRevIter
A reverse read-write iterator structure.
RwRevPrefix
A reverse read-write prefix iterator structure.
RwRevRange
A reverse read-write range iterator structure.
RwTxn
A read-write transaction.

Enums§

CompactionOption
Whether to perform compaction while copying an environment.
DefaultComparator
A representation of LMDB’s default comparator behavior.
Error
An error that encapsulates all possible errors in this crate.
FlagSetMode
Whether to enable or disable flags in Env::set_flags.
MdbError
An LMDB error kind.
Unspecified
An unspecified type.

Traits§

BytesDecode
A trait that represents a decoding structure.
BytesEncode
A trait that represents an encoding structure.
Comparator
Define a custom key comparison function for a database.
LexicographicComparator
Define a lexicographic comparator, which is a special case of Comparator.

Functions§

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

Type Aliases§

BoxedError
A boxed Send + Sync + 'static error.
Result
Either a success or an Error.