macro_rules! try_cek {
($result:expr) => { ... };
}
Expand description
Propagates a catchable error as Ok(Err(_))
or returns the unwrapped value in Ok
.
You should use the try operator (?
) to propagate uncatchable errors before passing catchable
errors to try_cek
.
Input type: Result<T, CatchableErrorKind>
Output type: T
Return type of containing function: Result<Result<_, CatchableErrorKind>, _>
ยงExample
use snix_eval::{try_cek, CatchableErrorKind};
fn my_fn() -> Result<Result<i32, CatchableErrorKind>, MyUncatchableError> {
Ok(Ok(42))
}
let value: i32 = try_cek!(my_fn()?);
assert_eq!(value, 42);
fn my_other_fn() -> Result<Result<i32, CatchableErrorKind>, MyUncatchableError> {
Ok(Err(CatchableErrorKind::AssertionFailed))
}
try_cek!(my_other_fn()?); // results in `return Ok(Err(cek))`
unreachable!();