1use crate::{BranchNodeCompact, Nibbles};
2use alloy_primitives::B256;
3use reth_storage_errors::db::DatabaseError;
45/// In-memory implementations of trie cursors.
6mod in_memory;
78/// Cursor for iterating over a subtrie.
9pub mod subnode;
1011/// Noop trie cursor implementations.
12pub mod noop;
1314/// Mock trie cursor implementations.
15#[cfg(test)]
16pub mod mock;
1718pub use self::{in_memory::*, subnode::CursorSubNode};
1920/// Factory for creating trie cursors.
21#[auto_impl::auto_impl(&)]
22pub trait TrieCursorFactory {
23/// The account trie cursor type.
24type AccountTrieCursor: TrieCursor;
25/// The storage trie cursor type.
26type StorageTrieCursor: TrieCursor;
2728/// Create an account trie cursor.
29fn account_trie_cursor(&self) -> Result<Self::AccountTrieCursor, DatabaseError>;
3031/// Create a storage tries cursor.
32fn storage_trie_cursor(
33&self,
34 hashed_address: B256,
35 ) -> Result<Self::StorageTrieCursor, DatabaseError>;
36}
3738/// A cursor for navigating a trie that works with both Tables and DupSort tables.
39#[auto_impl::auto_impl(&mut, Box)]
40pub trait TrieCursor: Send + Sync {
41/// Move the cursor to the key and return if it is an exact match.
42fn seek_exact(
43&mut self,
44 key: Nibbles,
45 ) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
4647/// Move the cursor to the key and return a value matching of greater than the key.
48fn seek(&mut self, key: Nibbles)
49 -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
5051/// Move the cursor to the next key.
52fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
5354/// Get the current entry.
55fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError>;
56}