From 67e3b674babefff33560b053f26bab7b222ee03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 25 Apr 2024 15:51:52 +0200 Subject: [PATCH] Improve the README and some doc links --- README.md | 39 ++++++++++++++++++++++++++++++++++++--- heed/src/env.rs | 2 +- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 66dbd67..8a16716 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,44 @@ [![dependency status](https://deps.rs/repo/github/meilisearch/heed/status.svg)](https://deps.rs/repo/github/meilisearch/heed) [![Build](https://github.com/meilisearch/heed/actions/workflows/rust.yml/badge.svg)](https://github.com/meilisearch/heed/actions/workflows/rust.yml) -A Rust-centric [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) abstraction with minimal overhead. +A Rust-centric [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) abstraction with minimal overhead. This library enables the storage of various Rust types within LMDB, extending support to include Serde-compatible types. -`heed` enables the storage of various Rust types within LMDB, extending support to include Serde-compatible types. +## Simple Example Usage -For usage examples, see [heed/examples/](heed/examples/). +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/](heed/examples/). To see more advanced usage techniques go check our [Cookbook](https://docs.rs/heed/latest/heed/cookbook/index.html). + +```rust +use std::fs; +use std::path::Path; +use heed::{EnvOpenOptions, Database}; +use heed::types::*; + +fn main() -> Result<(), Box> { + let env = unsafe { EnvOpenOptions::new().open("my-first-db")? }; + + // We open the default unnamed database + let mut wtxn = env.write_txn()?; + let db: Database> = 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 diff --git a/heed/src/env.rs b/heed/src/env.rs index 4bbd1cf..3bc09c8 100644 --- a/heed/src/env.rs +++ b/heed/src/env.rs @@ -449,7 +449,7 @@ pub enum CompactionOption { Disabled, } -/// Whether to enable or disable flags in [`Env::set_flag`]. +/// Whether to enable or disable flags in [`Env::set_flags`]. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum FlagSetMode { /// Enable the flags.