1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2026 James Gober.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//! # emdb
//!
//! A lightweight, high-performance embedded database for Rust.
//!
//! This crate provides an in-memory key/value store with optional TTL handling
//! and nested-key ergonomics.
//!
//! The API is still pre-1.0 and may change. See the repository for roadmap and
//! status:
//! <https://github.com/jamesgober/emdb-rs>
//!
//! ## Examples
//!
//! Base key/value usage:
//!
//! ```rust
//! use emdb::Emdb;
//!
//! let mut db = Emdb::open_in_memory();
//! db.insert("name", "emdb")?;
//! assert_eq!(db.get("name")?, Some(b"emdb".to_vec()));
//! # Ok::<(), emdb::Error>(())
//! ```
//!
//! Persistent usage:
//!
//! ```rust
//! use emdb::Emdb;
//!
//! let path = std::env::temp_dir().join("emdb-doc-example.emdb");
//! {
//! let mut db = Emdb::open(&path)?;
//! db.insert("name", "emdb")?;
//! db.flush()?;
//! }
//! let db = Emdb::open(&path)?;
//! assert_eq!(db.get("name")?, Some(b"emdb".to_vec()));
//! # let _cleanup = std::fs::remove_file(path);
//! # Ok::<(), emdb::Error>(())
//! ```
//!
//! TTL usage:
//!
//! ```rust
//! # #[cfg(feature = "ttl")]
//! # {
//! use std::time::Duration;
//!
//! use emdb::{Emdb, Ttl};
//!
//! let mut db = Emdb::builder()
//! .default_ttl(Duration::from_secs(60))
//! .build()?;
//! db.insert_with_ttl("session", "token", Ttl::Default)?;
//! assert!(db.ttl("session")?.is_some());
//! # }
//! # Ok::<(), emdb::Error>(())
//! ```
//!
//! Nested usage:
//!
//! ```rust
//! # #[cfg(feature = "nested")]
//! # {
//! use emdb::Emdb;
//!
//! let mut db = Emdb::open_in_memory();
//! let mut profile = db.focus("profile");
//! profile.set("name", "james")?;
//! assert_eq!(profile.get("name")?, Some(b"james".to_vec()));
//! # }
//! # Ok::<(), emdb::Error>(())
//! ```
pub use EmdbBuilder;
pub use Emdb;
pub use ;
pub use Focus;
pub use FlushPolicy;
pub use Ttl;