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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Idiomatic and safe Rust bindings for [libmdbx].
//!
//! # Overview
//!
//! [libmdbx] is a high-performance embedded key-value database based on
//! LMDB, with additional features like nested transactions, automatic
//! compaction, and improved durability options.
//!
//! This crate provides a safe, idiomatic Rust interface for:
//! - Creating and managing memory-mapped database environments
//! - Performing transactional read and write operations
//! - Iterating over key-value pairs with cursors
//! - Custom serialization via the [`TableObject`] trait
//!
//! # Quick Start
//!
//! Databases are stored in a directory on disk. The following example
//! demonstrates creating an environment, writing a key-value pair, and
//! reading it back.
//!
//! ```no_run
//! use signet_libmdbx::{
//! Environment, DatabaseFlags, WriteFlags, Geometry, MdbxResult,
//! };
//! use std::path::Path;
//!
//! fn main() -> MdbxResult<()> {
//! // Open an environment (creates directory if needed)
//! let env = Environment::builder()
//! .set_geometry(Geometry {
//! size: Some(0..(1024 * 1024 * 1024)), // up to 1GB
//! ..Default::default()
//! })
//! .open(Path::new("/tmp/my_database"))?;
//!
//! // Write data in a read-write transaction
//! let txn = env.begin_rw_txn()?;
//! let db = txn.create_db(None, DatabaseFlags::empty())?;
//! txn.put(db.dbi(), b"hello", b"world", WriteFlags::empty())?;
//! txn.commit()?;
//!
//! // Read data in a read-only transaction
//! let txn = env.begin_ro_txn()?;
//! let db = txn.open_db(None)?;
//! let value: Option<Vec<u8>> = txn.get(db.dbi(), b"hello").expect("read failed");
//! assert_eq!(value.as_deref(), Some(b"world".as_slice()));
//!
//! Ok(())
//! }
//! ```
//!
//! # Key Concepts
//!
//! - **Environment**: A directory containing one or more databases. Created
//! via [`Environment::builder()`].
//! - **Transaction**: All operations occur within transactions. Use
//! [`Environment::begin_ro_txn()`] for reads and
//! [`Environment::begin_rw_txn()`] for read-writes.
//! - [`Database`] A named or unnamed key-value store within an environment.
//! Opened via [`Transaction::open_db()`] or created via
//! [`Transaction::create_db()`].
//! - [`Cursor`]: Enables iteration and positioned access within a database.
//! Created via [`Transaction::cursor()`].
//!
//! # Feature Flags
//!
//! - `return-borrowed`: When enabled, iterators return borrowed data
//! (`Cow::Borrowed`) whenever possible, avoiding allocations. This is faster
//! but the data may change if the transaction modifies it later, which could
//! trigger undefined behavior. When disabled (default), dirty pages in write
//! transactions trigger copies for safety.
//! - `read-tx-timeouts`: Enables automatic timeout handling for read
//! transactions that block writers. Useful for detecting stuck readers.
//!
//! # Custom Types with [`TableObject`]
//!
//! Implement [`TableObject`] to decode custom types directly from the
//! database:
//!
//! ```
//! # use std::borrow::Cow;
//! use signet_libmdbx::{TableObject, ReadResult, MdbxError};
//!
//! struct MyKey([u8; 32]);
//!
//! impl TableObject<'_> for MyKey {
//! fn decode_borrow(data: Cow<'_, [u8]>) -> ReadResult<Self> {
//! let arr: [u8; 32] = data.as_ref().try_into()
//! .map_err(|_| MdbxError::DecodeErrorLenDiff)?;
//! Ok(Self(arr))
//! }
//! }
//! ```
//!
//! See the [`TableObject`] docs for more examples.
//!
//! # Provenance
//!
//! Forked from [reth-libmdbx], which was forked from an earlier Apache
//! licensed version of the `libmdbx-rs` crate. Original LMDB bindings from
//! [lmdb-rs].
//!
//! [libmdbx]: https://github.com/erthink/libmdbx
//! [reth-libmdbx]: https://github.com/paradigmxyz/reth
//! [lmdb-rs]: https://github.com/mozilla/lmdb-rs
pub extern crate signet_mdbx_sys as ffi;
pub use *;
pub use crateMaxReadTransactionDuration;
pub use ;
pub use *;
pub use ;
pub use ;