Skip to main content

revm_database_interface/
state_hook.rs

1//! State commit hook.
2
3use crate::state::EvmState;
4
5/// A hook that is called when state changes are committed.
6pub trait OnStateHook: Send + 'static {
7    /// Invoked with the state being committed.
8    fn on_state(&mut self, state: &EvmState);
9}
10
11impl<F> OnStateHook for F
12where
13    F: FnMut(&EvmState) + Send + 'static,
14{
15    fn on_state(&mut self, state: &EvmState) {
16        self(state)
17    }
18}
19
20/// An [`OnStateHook`] that does nothing.
21#[derive(Default, Debug, Clone)]
22#[non_exhaustive]
23pub struct NoopHook;
24
25impl OnStateHook for NoopHook {
26    fn on_state(&mut self, _state: &EvmState) {}
27}