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

  • “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.
  • Construct an ad-hoc error from a string or existing non-anyhow error value.
  • “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.
  • Return early with an error.

Structs

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

Enums

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

Type Definitions