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
//! Iterator types for traversing MDBX databases.
//!
//! This module provides lending iterators over key-value pairs in MDBX
//! databases. The iterators support both borrowed and owned access patterns.
//!
//! # Iterator Types
//!
//! | Iterator | Yields | Use Case |
//! |----------|--------|----------|
//! | [`Iter`] | `(Key, Value)` | Base iterator, configurable cursor op |
//! | [`IterDup`] | `(Key, Value)` | Flat iteration over DUPSORT tables |
//! | [`IterDupOfKey`] | `Value` | Single-key DUPSORT iteration |
//! | [`IterDupFixed`] | `(Key, Value)` | Flat iteration over DUPFIXED tables |
//! | [`IterDupFixedOfKey`] | `Value` | Single-key DUPFIXED iteration |
//!
//! # Borrowing vs Owning
//!
//! Iterators provide two ways to access data:
//!
//! - [`borrow_next()`](Iter::borrow_next): Returns data potentially borrowed
//! from the database. Requires the `Key` and `Value` types to implement
//! [`TableObject<'tx>`](crate::TableObject). This can avoid allocations
//! when using `Cow<'tx, [u8]>`.
//!
//! - [`owned_next()`](Iter::owned_next): Returns owned data. Requires
//! [`TableObjectOwned`](crate::TableObjectOwned). Always safe but may allocate.
//!
//! The standard [`Iterator`] trait is implemented via `owned_next()`.
//!
//! # Dirty Page Handling
//!
//! In read-write transactions, database pages may be "dirty" (modified but
//! not yet committed). The behavior of `Cow<[u8]>` depends on the
//! `return-borrowed` feature:
//!
//! - **With `return-borrowed`**: Always returns `Cow::Borrowed`, even for
//! dirty pages. This is faster but the data may change if the transaction
//! modifies it later.
//!
//! - **Without `return-borrowed`** (default): Dirty pages are copied to
//! `Cow::Owned`. This is safer but allocates more.
//!
//! # Example
//!
//! ```no_run
//! # use signet_libmdbx::Environment;
//! # use std::path::Path;
//! # let env = Environment::builder().open(Path::new("/tmp/iter_example")).unwrap();
//! let txn = env.begin_ro_sync().unwrap();
//! let db = txn.open_db(None).unwrap();
//! let mut cursor = txn.cursor(db).unwrap();
//!
//! // Iterate using the standard Iterator trait (owned)
//! for result in cursor.iter_start::<Vec<u8>, Vec<u8>>().unwrap() {
//! let (key, value) = result.expect("decode error");
//! println!("{:?} => {:?}", key, value);
//! }
//! ```
pub use Iter;
pub use IterDup;
pub use IterDupOfKey;
pub use IterDupFixed;
pub use IterDupFixedOfKey;
/// An item from a duplicate-key iterator.
///
/// This enum avoids cloning the key for every value when iterating
/// over databases with duplicate keys. The key is only provided when
/// it changes.