rusty-man/tests/snapshots/output__1.56.0_html_macro_anyhow_ensure.snap
Robin Krahl 6dc75f0c5d
Add support for Rust 1.54.0, 1.55.0, 1.56.0
This patch adds tests for Rust 1.54.0, 1.55.0 and 1.56.0.  To make the
tests pass, we have to take care of some changes like more details
elements and changed heading levels.  To make it easier to generate the
tests for new Rust versions, we also add two bash scripts that take care
of that.
2021-10-26 23:29:54 +02:00

39 lines
1.2 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
source: tests/output.rs
expression: "get_stdout(path, &[\"anyhow::ensure\"])"
---
anyhow Macro anyhow::ensure rusty-man
SYNOPSIS
macro_rules! ensure {
($cond : expr $(,) ?) => { ... };
($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(``anyhow!($args...)``); }`.
The surrounding functions or closures return value is required to be
`Result<_,``anyhow::Error``>`.
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);`