Skip to content

Commit 1036cab

Browse files
committed
feat: new macros
1 parent ad8a860 commit 1036cab

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ pub use fill::{Block, Cfg, NoopBlock, NoopCfg, Tx};
380380
mod lifecycle;
381381
pub use lifecycle::{ethereum_receipt, BlockOutput, PostTx, PostflightResult};
382382

383+
mod macros;
384+
383385
mod states;
384386
pub(crate) use states::sealed::*;
385387
pub use states::{

src/macros.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// Unwraps a Result, returning the value if successful, or returning an errored `Trevm` if not.
2+
#[macro_export]
3+
macro_rules! unwrap_or_trevm_err {
4+
($e:expr, $trevm:expr) => {
5+
match $e {
6+
Ok(val) => val,
7+
Err(e) => return Err($trevm.errored(e.into())),
8+
}
9+
};
10+
}
11+
12+
/// Executes a condition, returning an errored `Trevm` if not successful.
13+
#[macro_export]
14+
macro_rules! trevm_ensure {
15+
($cond:expr, $trevm:expr, $err:expr) => {
16+
if !$cond {
17+
trevm_bail!($trevm, $err);
18+
}
19+
};
20+
}
21+
22+
/// Returns an errored `Trevm` with the provided error.
23+
#[macro_export]
24+
macro_rules! trevm_bail {
25+
($trevm:expr, $err:expr) => {
26+
return Err($trevm.errored($err))
27+
};
28+
}

0 commit comments

Comments
 (0)