reth_trie/hashed_cursor/
noop.rs

1use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor};
2use alloy_primitives::{B256, U256};
3use core::marker::PhantomData;
4use reth_primitives_traits::Account;
5use reth_storage_errors::db::DatabaseError;
6
7/// Noop hashed cursor factory.
8#[derive(Clone, Default, Debug)]
9#[non_exhaustive]
10pub struct NoopHashedCursorFactory;
11
12impl HashedCursorFactory for NoopHashedCursorFactory {
13    type AccountCursor<'a>
14        = NoopHashedCursor<Account>
15    where
16        Self: 'a;
17    type StorageCursor<'a>
18        = NoopHashedCursor<U256>
19    where
20        Self: 'a;
21
22    fn hashed_account_cursor(&self) -> Result<Self::AccountCursor<'_>, DatabaseError> {
23        Ok(NoopHashedCursor::default())
24    }
25
26    fn hashed_storage_cursor(
27        &self,
28        _hashed_address: B256,
29    ) -> Result<Self::StorageCursor<'_>, DatabaseError> {
30        Ok(NoopHashedCursor::default())
31    }
32}
33
34/// Generic noop hashed cursor.
35#[derive(Debug)]
36pub struct NoopHashedCursor<V> {
37    _marker: PhantomData<V>,
38}
39
40impl<V> Default for NoopHashedCursor<V> {
41    fn default() -> Self {
42        Self { _marker: PhantomData }
43    }
44}
45
46impl<V> HashedCursor for NoopHashedCursor<V>
47where
48    V: std::fmt::Debug,
49{
50    type Value = V;
51
52    fn seek(&mut self, _key: B256) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
53        Ok(None)
54    }
55
56    fn next(&mut self) -> Result<Option<(B256, Self::Value)>, DatabaseError> {
57        Ok(None)
58    }
59
60    fn reset(&mut self) {
61        // Noop
62    }
63}
64
65impl HashedStorageCursor for NoopHashedCursor<U256> {
66    fn is_storage_empty(&mut self) -> Result<bool, DatabaseError> {
67        Ok(true)
68    }
69
70    fn set_hashed_address(&mut self, _hashed_address: B256) {
71        // Noop
72    }
73}