@@ -5,6 +5,42 @@ use revm::{
55} ;
66use std:: { collections:: BTreeMap , convert:: Infallible , sync:: Arc } ;
77
8+ /// Trait for types that can be used to connect to a database.
9+ ///
10+ /// Connectors should contain configuration information like filesystem paths.
11+ /// They are intended to enable parallel instantiation of multiple EVMs in
12+ /// multiple threads sharing some database configuration
13+ ///
14+ /// `DbConnect` is blanket implemented for clonable [`Database`] types by
15+ /// simply cloning the database instance. This allows already-instantiated DBs
16+ /// to be used as connectors, however, if the [`Database`] uses a shared
17+ /// resource like a file or network connection, care should be taken to ensure
18+ /// that the implementation does not share uintended state between EVM
19+ /// instances.
20+ pub trait DbConnect : Sync {
21+ /// The database type returned when connecting.
22+ type Database : Database ;
23+
24+ /// The error type returned when connecting to the database.
25+ type Error : core:: error:: Error ;
26+
27+ /// Connect to the database.
28+ fn connect ( & self ) -> Result < Self :: Database , Self :: Error > ;
29+ }
30+
31+ impl < Db > DbConnect for Db
32+ where
33+ Db : Database + Clone + Sync ,
34+ {
35+ type Database = Self ;
36+
37+ type Error = Infallible ;
38+
39+ fn connect ( & self ) -> Result < Self :: Database , Self :: Error > {
40+ Ok ( self . clone ( ) )
41+ }
42+ }
43+
844/// Abstraction trait covering types that accumulate state changes into a
945/// [`BundleState`]. The prime example of this is [`State`]. These types are
1046/// use to accumulate state changes during the execution of a sequence of
0 commit comments