Skip to content
Myr

Touch up ensure macro documentation

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

authored by David Tolnay · committed by David Tolnay · parent c5e1ca0 · Browse files · 1 file+4 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+4 added−6 removed

  • other:+4 added−6 removed

1 file+4 added−6 removed

modified:src/lib.rs+4 added-6 removed
291 unmodified lines
292}293294/// Return early with an error if a condition is not satisfied.295///296/// This macro is equivalent to `if !condition { return Err(From::from($err)) }`.296/// This macro is equivalent to `if !$cond { return Err(From::from($err)); }`.297///298/// Similar to `assert!`, `ensure!` takes a condition and exits the function299/// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error`,300/// it does not panic.298/// Analogously to `assert!`, `ensure!` takes a condition and exits the function299/// if the condition fails. Unlike `assert!`, `ensure!` returns an `Error`300/// rather than panicking.301///302/// # Example303///304/// ```305/// # use anyhow::{ensure, Result};306/// #307/// #307/// # fn main() -> Result<()> {308/// # let user = 0;310/// # let resource = 0;309/// #310/// ensure!(user == 0, "only user 0 is allowed");311/// # Ok(())312/// # }
105 unmodified lines