Module prelude

Module prelude 

Source
Expand description

A “prelude” module providing a collection of useful names, without causing compiler complaints about the ones you don’t use.

Provided names are:

  • The core anyhow::Error type
  • The core anyhow::Result type, which is Result<T, anyhow::Error>
  • The anyhow! macro to create an Error value from a string-format expression
  • The bail! macro: bail!(...) = return Err(anyhow!(...))
  • The ensure! macro: ensure!(cond, err) = if !cond { bail!(err); }
  • The atry! macro for annotated question-mark behavior
  • The a_ok_or! macro for annotated, fallibale Option unwrapping
  • Rust’s std::result::Result type aliased as StdResult for convenience

Macros§

a_ok_or
“annotated ok_or” — like Option::ok_or_else()?, but with the ability to add extended context to the error. This yields an AnnotatedMessage as its error type.
anyhow
Construct an ad-hoc error from a string or existing non-anyhow error value.
atry
“Annotated try” — like try!, but with the ability to add extended context to the error message. This tries to provide a bit more syntactic sugar than anyhow’s with_context(), and it supports our AnnotatedMessage context type.
bail
Return early with an error.
ensure
Return early with an error if a condition is not satisfied.

Structs§

Error
The Error type, a wrapper around a dynamic error type.

Enums§

StdResult
Result is a type that represents either success (Ok) or failure (Err).

Type Aliases§

Result
Result<T, Error>