Skip to content

Commit b3f31fc

Browse files
authored
feat: add helper function to mape EVMError's Database error variant (bluealloy#1567)
1 parent aaff133 commit b3f31fc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/primitives/src/result.rs

+16
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ pub enum EVMError<DBError> {
152152
Precompile(String),
153153
}
154154

155+
impl<DBError> EVMError<DBError> {
156+
/// Maps a `DBError` to a new error type using the provided closure, leaving other variants unchanged.
157+
pub fn map_db_err<F, E>(self, op: F) -> EVMError<E>
158+
where
159+
F: FnOnce(DBError) -> E,
160+
{
161+
match self {
162+
Self::Transaction(e) => EVMError::Transaction(e),
163+
Self::Header(e) => EVMError::Header(e),
164+
Self::Database(e) => EVMError::Database(op(e)),
165+
Self::Precompile(e) => EVMError::Precompile(e),
166+
Self::Custom(e) => EVMError::Custom(e),
167+
}
168+
}
169+
}
170+
155171
#[cfg(feature = "std")]
156172
impl<DBError: std::error::Error + 'static> std::error::Error for EVMError<DBError> {
157173
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {

0 commit comments

Comments
 (0)