13 releases

0.20.0 Apr 26, 2024
0.20.0-alpha.9 Nov 27, 2023
0.20.0-alpha.4 Aug 23, 2023
0.20.0-alpha.3 Jul 13, 2023
0.7.0 Apr 26, 2020

#1198 in Database interfaces

Download history 9403/week @ 2024-03-14 9724/week @ 2024-03-21 6917/week @ 2024-03-28 10147/week @ 2024-04-04 8687/week @ 2024-04-11 14180/week @ 2024-04-18 17025/week @ 2024-04-25 16891/week @ 2024-05-02 17469/week @ 2024-05-09 19275/week @ 2024-05-16 19749/week @ 2024-05-23 23883/week @ 2024-05-30 19808/week @ 2024-06-06 19548/week @ 2024-06-13 22395/week @ 2024-06-20 19036/week @ 2024-06-27

85,346 downloads per month
Used in 16 crates (3 directly)

MIT license

8KB

heed

License Crates.io Docs dependency status Build

A Rust-centric LMDB abstraction with minimal overhead. This library enables the storage of various Rust types within LMDB, extending support to include Serde-compatible types.

Simple Example Usage

Here is an example on how to store and read entries into LMDB in a safe and ACID way. For usage examples, see heed/examples/. To see more advanced usage techniques go check our Cookbook.

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

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let env = unsafe { EnvOpenOptions::new().open("my-first-db")? };

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

    // We open 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()?;

    // We open 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));

    Ok(())
}

Building from Source

You can use this command to clone the repository:

git clone --recursive https://github.com/meilisearch/heed.git
cd heed
cargo build

However, if you already cloned it and forgot to initialize the submodules, execute the following command:

git submodule update --init

No runtime deps