1use core::fmt::Debug;
3use core::ops::{Deref, DerefMut};
4
5#[derive(Debug, Clone)]
7pub struct Evm<CTX, INSP, I, P> {
8 pub ctx: CTX,
10 pub inspector: INSP,
13 pub instruction: I,
16 pub precompiles: P,
19}
20
21impl<CTX, I, P> Evm<CTX, (), I, P> {
22 pub fn new(ctx: CTX, instruction: I, precompiles: P) -> Self {
26 Evm {
27 ctx,
28 inspector: (),
29 instruction,
30 precompiles,
31 }
32 }
33}
34
35impl<CTX, I, INSP, P> Evm<CTX, INSP, I, P> {
36 pub fn new_with_inspector(ctx: CTX, inspector: INSP, instruction: I, precompiles: P) -> Self {
38 Evm {
39 ctx,
40 inspector,
41 instruction,
42 precompiles,
43 }
44 }
45}
46
47impl<CTX, INSP, I, P> Evm<CTX, INSP, I, P> {
48 pub fn with_inspector<OINSP>(self, inspector: OINSP) -> Evm<CTX, OINSP, I, P> {
50 Evm {
51 ctx: self.ctx,
52 inspector,
53
54 instruction: self.instruction,
55 precompiles: self.precompiles,
56 }
57 }
58
59 pub fn with_precompiles<OP>(self, precompiles: OP) -> Evm<CTX, INSP, I, OP> {
61 Evm {
62 ctx: self.ctx,
63 inspector: self.inspector,
64 instruction: self.instruction,
65 precompiles,
66 }
67 }
68
69 pub fn into_inspector(self) -> INSP {
71 self.inspector
72 }
73}
74
75impl<CTX, INSP, I, P> Deref for Evm<CTX, INSP, I, P> {
76 type Target = CTX;
77
78 fn deref(&self) -> &Self::Target {
79 &self.ctx
80 }
81}
82
83impl<CTX, INSP, I, P> DerefMut for Evm<CTX, INSP, I, P> {
84 fn deref_mut(&mut self) -> &mut Self::Target {
85 &mut self.ctx
86 }
87}