display-error-chain 0.2.2

Formats a standard error and its sources
Documentation
  • Coverage
  • 100%
    10 out of 10 items documented2 out of 7 items with examples
  • Size
  • Source code size: 23.88 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 714.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mexus/display-error-chain
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mexus

display-error-chain

A lightweight library for displaying errors and their sources.

A sample output:

macro_rules! impl_error {
    // ...
}

// `TopLevel` is caused by a `MidLevel`.
#[derive(Debug)]
struct TopLevel;
impl_error!(TopLevel, "top level", Some(&MidLevel));

// `MidLevel` is caused by a `LowLevel`.
#[derive(Debug)]
struct MidLevel;
impl_error!(MidLevel, "mid level", Some(&LowLevel));

// `LowLevel` is the cause itself.
#[derive(Debug)]
struct LowLevel;
impl_error!(LowLevel, "low level", None);

// Now let's see how it works:
let formatted = display_error_chain::DisplayErrorChain::new(&TopLevel).to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

// Or with `.chain()` helper:
use display_error_chain::ErrorChainExt as _;
let formatted = TopLevel.chain().to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

// Or even with `.into_chain()` helper to consume the error.
use display_error_chain::ErrorChainExt as _;
let formatted = TopLevel.into_chain().to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

License: Apache-2.0/MIT