Skip to content

Commit

Permalink
feat: add helper function to mape EVMError's Database error variant (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jun 25, 2024
1 parent aaff133 commit b3f31fc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ pub enum EVMError<DBError> {
Precompile(String),
}

impl<DBError> EVMError<DBError> {
/// Maps a `DBError` to a new error type using the provided closure, leaving other variants unchanged.
pub fn map_db_err<F, E>(self, op: F) -> EVMError<E>
where
F: FnOnce(DBError) -> E,
{
match self {
Self::Transaction(e) => EVMError::Transaction(e),
Self::Header(e) => EVMError::Header(e),
Self::Database(e) => EVMError::Database(op(e)),
Self::Precompile(e) => EVMError::Precompile(e),
Self::Custom(e) => EVMError::Custom(e),
}
}
}

#[cfg(feature = "std")]
impl<DBError: std::error::Error + 'static> std::error::Error for EVMError<DBError> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Expand Down

0 comments on commit b3f31fc

Please sign in to comment.