revm_context/
evm.rs

1use core::fmt::Debug;
2use core::ops::{Deref, DerefMut};
3
4#[derive(Debug)]
5pub struct Evm<CTX, INSP, I, P> {
6    pub data: EvmData<CTX, INSP>,
7    pub instruction: I,
8    pub precompiles: P,
9}
10
11#[derive(Debug)]
12pub struct EvmData<CTX, INSP> {
13    pub ctx: CTX,
14    pub inspector: INSP,
15}
16
17impl<CTX, I, P> Evm<CTX, (), I, P> {
18    pub fn new(ctx: CTX, instruction: I, precompiles: P) -> Evm<CTX, (), I, P> {
19        Evm {
20            data: EvmData { ctx, inspector: () },
21            instruction,
22            precompiles,
23        }
24    }
25}
26
27impl<CTX, I, INSP, P> Evm<CTX, INSP, I, P> {
28    pub fn new_with_inspector(ctx: CTX, inspector: INSP, instruction: I, precompiles: P) -> Self {
29        Evm {
30            data: EvmData { ctx, inspector },
31            instruction,
32            precompiles,
33        }
34    }
35}
36
37impl<CTX, INSP, I, P> Evm<CTX, INSP, I, P> {
38    /// Consumed self and returns new Evm type with given Inspector.
39    pub fn with_inspector<OINSP>(self, inspector: OINSP) -> Evm<CTX, OINSP, I, P> {
40        Evm {
41            data: EvmData {
42                ctx: self.data.ctx,
43                inspector,
44            },
45            instruction: self.instruction,
46            precompiles: self.precompiles,
47        }
48    }
49
50    /// Consumes self and returns new Evm type with given Precompiles.
51    pub fn with_precompiles<OP>(self, precompiles: OP) -> Evm<CTX, INSP, I, OP> {
52        Evm {
53            data: self.data,
54            instruction: self.instruction,
55            precompiles,
56        }
57    }
58
59    /// Consumes self and returns inner Inspector.
60    pub fn into_inspector(self) -> INSP {
61        self.data.inspector
62    }
63}
64
65impl<CTX, INSP, I, P> Deref for Evm<CTX, INSP, I, P> {
66    type Target = CTX;
67
68    fn deref(&self) -> &Self::Target {
69        &self.data.ctx
70    }
71}
72
73impl<CTX, INSP, I, P> DerefMut for Evm<CTX, INSP, I, P> {
74    fn deref_mut(&mut self) -> &mut Self::Target {
75        &mut self.data.ctx
76    }
77}