mz_ore::error

Trait ErrorExt

Source
pub trait ErrorExt: Error {
    // Provided methods
    fn display_with_causes(&self) -> ErrorChainFormatter<&Self> { ... }
    fn to_string_with_causes(&self) -> String { ... }
}
Expand description

Extension methods for std::error::Error.

Provided Methods§

Source

fn display_with_causes(&self) -> ErrorChainFormatter<&Self>

Returns a type that displays the error, along with the chain of source errors or causes, if there are any.

§Examples
use anyhow::anyhow;
use mz_ore::error::ErrorExt;

let error = anyhow!("inner");
let error = error.context("context");
assert_eq!(format!("error: ({})", error.display_with_causes()), "error: (context: inner)");
Source

fn to_string_with_causes(&self) -> String

Converts self to a string String, along with the chain of source errors or causes, if there are any.

§Examples

Basic usage:

use anyhow::anyhow;
use mz_ore::error::ErrorExt;

let error = anyhow!("inner");
let error = error.context("context");
assert_eq!(error.to_string_with_causes(), "context: inner");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E: Error + ?Sized> ErrorExt for E