1use core::fmt::Debug;
3use core::ops::{Deref, DerefMut};
4
5use context_interface::FrameStack;
6
7#[derive(Debug, Clone)]
9pub struct Evm<CTX, INSP, I, P, F> {
10 pub ctx: CTX,
12 pub inspector: INSP,
15 pub instruction: I,
18 pub precompiles: P,
21 pub frame_stack: FrameStack<F>,
23}
24
25impl<CTX, I, P, F> Evm<CTX, (), I, P, F> {
26 pub fn new(ctx: CTX, instruction: I, precompiles: P) -> Self {
30 Evm {
31 ctx,
32 inspector: (),
33 instruction,
34 precompiles,
35 frame_stack: FrameStack::new(),
36 }
37 }
38}
39
40impl<CTX, I, INSP, P, F> Evm<CTX, INSP, I, P, F> {
41 pub fn new_with_inspector(ctx: CTX, inspector: INSP, instruction: I, precompiles: P) -> Self {
43 Evm {
44 ctx,
45 inspector,
46 instruction,
47 precompiles,
48 frame_stack: FrameStack::new(),
49 }
50 }
51}
52
53impl<CTX, INSP, I, P, F> Evm<CTX, INSP, I, P, F> {
54 pub fn with_inspector<OINSP>(self, inspector: OINSP) -> Evm<CTX, OINSP, I, P, F> {
56 Evm {
57 ctx: self.ctx,
58 inspector,
59
60 instruction: self.instruction,
61 precompiles: self.precompiles,
62 frame_stack: self.frame_stack,
63 }
64 }
65
66 pub fn with_precompiles<OP>(self, precompiles: OP) -> Evm<CTX, INSP, I, OP, F> {
68 Evm {
69 ctx: self.ctx,
70 inspector: self.inspector,
71 instruction: self.instruction,
72 precompiles,
73 frame_stack: self.frame_stack,
74 }
75 }
76
77 pub fn into_inspector(self) -> INSP {
79 self.inspector
80 }
81}
82
83impl<CTX, INSP, I, P, F> Deref for Evm<CTX, INSP, I, P, F> {
84 type Target = CTX;
85
86 fn deref(&self) -> &Self::Target {
87 &self.ctx
88 }
89}
90
91impl<CTX, INSP, I, P, F> DerefMut for Evm<CTX, INSP, I, P, F> {
92 fn deref_mut(&mut self) -> &mut Self::Target {
93 &mut self.ctx
94 }
95}