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.
9mod subnode;
1011/// Noop trie cursor implementations.
12pub mod noop;
1314pub use self::{in_memory::*, subnode::CursorSubNode};
1516/// Factory for creating trie cursors.
17#[auto_impl::auto_impl(&)]
18pub trait TrieCursorFactory {
19/// The account trie cursor type.
20type AccountTrieCursor: TrieCursor;
21/// The storage trie cursor type.
22type StorageTrieCursor: TrieCursor;
2324/// Create an account trie cursor.
25fn account_trie_cursor(&self) -> Result<Self::AccountTrieCursor, DatabaseError>;
2627/// Create a storage tries cursor.
28fn storage_trie_cursor(
29&self,
30 hashed_address: B256,
31 ) -> Result<Self::StorageTrieCursor, DatabaseError>;
32}
3334/// A cursor for navigating a trie that works with both Tables and DupSort tables.
35#[auto_impl::auto_impl(&mut, Box)]
36pub trait TrieCursor: Send + Sync {
37/// Move the cursor to the key and return if it is an exact match.
38fn seek_exact(
39&mut self,
40 key: Nibbles,
41 ) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
4243/// Move the cursor to the key and return a value matching of greater than the key.
44fn seek(&mut self, key: Nibbles)
45 -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
4647/// Move the cursor to the next key.
48fn next(&mut self) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError>;
4950/// Get the current entry.
51fn current(&mut self) -> Result<Option<Nibbles>, DatabaseError>;
52}