rusty-man/tests/snapshots/output__1.50.0_macro_anyhow_ensure.snap
Robin Krahl ea183be56d
Add tests for Rust 1.50.0
This patch adds tests for Rust 1.50.0 which we can mostly copy from
1.49.0.  There is only a small change to the abbreviated descriptions in
the search index and to edition-specific code.
2021-06-05 21:14:58 +02:00

34 lines
1.0 KiB
Plaintext

---
source: tests/output.rs
expression: "get_stdout(&[item])"
---
anyhow Macro anyhow::ensure rusty-man
SYNOPSIS
macro_rules! ensure {
($cond:expr, $msg:literal $(,)?) => { ... };
($cond:expr, $err:expr $(,)?) => { ... };
($cond:expr, $fmt:expr, $($arg:tt)*) => { ... };
}
DESCRIPTION
Return early with an error if a condition is not satisfied.
This macro is equivalent to `if !$cond { return Err(From::from($err)); }`.
Analogously to `assert!`, `ensure!` takes a condition and exits the function if the condition
fails. Unlike `assert!`, `ensure!` returns an `Error` rather than panicking.
# Example
ensure!(user == 0, "only user 0 is allowed");
#[derive(Error, Debug)]
enum ScienceError {
#[error("recursion limit exceeded")]
RecursionLimitExceeded,
...
}
ensure!(depth <= MAX_DEPTH, ScienceError::RecursionLimitExceeded);