n0_error

Macro anyerr

Source
macro_rules! anyerr {
    ($fmt:literal$(, $($arg:expr),* $(,)?)?) => { ... };
    ($err:expr, $fmt:literal$(, $($arg:expr),* $(,)?)?) => { ... };
    ($err:expr) => { ... };
}
Expand description

Converts a value into [AnyError].

  • anyerr!("msg") creates an error with just a message.
  • anyerr!("this failed at {a} with {}", b) creates an error with a formatted message
  • anyerr!(value) converts any impl StackError, impl std::error::Error, or impl Display into [AnyError].
  • anyerr!(value, "context string") works as above, but adds "context string" as [context`](Anyerr::context).
  • `anyerr!(value, “context {}”, foo) works as above, but with a formatted string as context

The forms that take value use autoref specialization to keep the most details possible: if given a [StackError] it uses [AnyError::from_stack], if given a std error, uses [AnyError::from_std], if given a value that impls Display it uses [AnyError::from_display] - in this order.