kvarn::prelude::utils::prelude::compact_str::core

Module error

1.81.0 · source
Expand description

Interfaces for working with Errors.

§Error Handling In Rust

The Rust language provides two complementary systems for constructing / representing, reporting, propagating, reacting to, and discarding errors. These responsibilities are collectively known as “error handling.” The components of the first system, the panic runtime and interfaces, are most commonly used to represent bugs that have been detected in your program. The components of the second system, Result, the error traits, and user defined types, are used to represent anticipated runtime failure modes of your program.

§The Panic Interfaces

The following are the primary interfaces of the panic system and the responsibilities they cover:

The following are the primary interfaces of the error system and the responsibilities they cover:

  • Result (Propagating, Reacting)
  • The Error trait (Reporting)
  • User defined types (Constructing / Representing)
  • match and downcast (Reacting)
  • The question mark operator (?) (Propagating)
  • The partially stable Try traits (Propagating, Constructing)
  • Termination (Reporting)

§Converting Errors into Panics

The panic and error systems are not entirely distinct. Often times errors that are anticipated runtime failures in an API might instead represent bugs to a caller. For these situations the standard library provides APIs for constructing panics with an Error as its source.

These functions are equivalent, they either return the