Skip to content
Myr

Merge pull request #114 from dtolnay/macrodoc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Improve documentation of anyhow!, bail!, ensure! macros

authored by David Tolnay · committed by GitHub · parents 33894b6, bcdec88 · Browse files · 1 file+19 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+19 added−6 removed

  • other:+19 added−6 removed

1 file+19 added−6 removed

modified:src/macros.rs+19 added-6 removed
1/// Return early with an error.2///3/// This macro is equivalent to `return Err(From::from($err))`.3/// This macro is equivalent to `return Err(`[`anyhow!($args...)`][anyhow!]`)`.4///5/// The surrounding function's or closure's return value is required to be6/// `Result<_,`[`anyhow::Error`][crate::Error]`>`.7///8/// # Example9///10/// ```11/// # use anyhow::{bail, Result};
52 unmodified lines
64}6566/// Return early with an error if a condition is not satisfied.67///65/// This macro is equivalent to `if !$cond { return Err(From::from($err)); }`.68/// This macro is equivalent to `if !$cond { return69/// Err(`[`anyhow!($args...)`][anyhow!]`); }`.70///71/// The surrounding function's or closure's return value is required to be72/// `Result<_,`[`anyhow::Error`][crate::Error]`>`.73///74/// Analogously to `assert!`, `ensure!` takes a condition and exits the function75/// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error`76/// rather than panicking.77///
51 unmodified lines
129 }130 };131}132126/// Construct an ad-hoc error from a string.133/// Construct an ad-hoc error from a string or existing non-`anyhow` error134/// value.135///128/// This evaluates to an `Error`. It can take either just a string, or a format129/// string with arguments. It also can take any custom type which implements130/// `Debug` and `Display`.136/// This evaluates to an [`Error`][crate::Error]. It can take either just a137/// string, or a format string with arguments. It also can take any custom type138/// which implements `Debug` and `Display`.139///140/// If called with a single argument whose type implements `std::error::Error`141/// (in addition to `Debug` and `Display`, which are always required), then that142/// Error impl's `source` is preserved as the `source` of the resulting143/// `anyhow::Error`.144///145/// # Example146///147/// ```148/// # type V = ();
28 unmodified lines