[go: up one dir, main page]

stable-eyre 0.1.3

A custom context for eyre that supports capturing Backtraces on stable
Documentation

stable-eyre

A custom context for eyre that captures a Backtrace on stable.

Explanation

This crate works by defining a Context type which implements eyre::EyreContext and a pair of type aliases for setting this context type as the parameter of eyre::Report.

pub type Report = eyre::Report<Context>;
pub type Result<T, E = Report> = core::result::Result<T, E>;

Setup

Add the following to your toml file:

[dependencies]
eyre = "0.3"
stable-eyre = "0.1"

And then import the type alias from color-eyre for eyre::Report or [eyre::Result].

use stable_eyre::Report;

// or

fn example(&self) -> stable_eyre::Result<()> {
    // ...
}

Example

use eyre::WrapErr;
use stable_eyre::Report;

fn main() -> Result<(), Report> {
    Ok(read_config()?)
}

fn read_file(path: &str) -> Result<(), Report> {
    Ok(std::fs::read_to_string(path).map(drop)?)
}

fn read_config() -> Result<(), Report> {
    read_file("fake_file")
        .wrap_err("Unable to read config")
}

License