griffin_core/support_macros.rs
1//! These macros were copied from `frame-support`.
2//!
3//! See discussion at <https://github.com/paritytech/substrate/issues/13456>
4//! to explain the repetition.
5
6/// Return Err of the expression: `return Err($expression);`.
7///
8/// Used as `fail!(expression)`.
9#[macro_export]
10macro_rules! fail {
11 ( $y:expr ) => {{
12 return Err($y.into());
13 }};
14}
15
16/// Evaluate `$x:expr` and if not true return `Err($y:expr)`.
17///
18/// Used as `ensure!(expression_to_ensure, expression_to_return_on_false)`.
19#[macro_export]
20macro_rules! ensure {
21 ( $x:expr, $y:expr $(,)? ) => {{
22 if !$x {
23 $crate::fail!($y);
24 }
25 }};
26}