Trait IntoEyreResult

Source
pub trait IntoEyreResult<T, I>
where I: IntoEyreReport,
{ // Required method fn into_eyre_result(self) -> Result<T, Report>; }
Expand description

Adds the into_eyre_result method on types that can be converted into Result<T, E>, converting them into Result<T, eyre::Report> instead.

Do not implement this trait. Importing the trait is sufficient due to blanket implementations. The trait is implemented on R if R can be converted into Result<_, E> and if E implements IntoEyreReport.

Required MethodsΒ§

Source

fn into_eyre_result(self) -> Result<T, Report>

Lossy conversion to return some type, for example a list of errors that may be empty, from functions returning eyre::Result, i.e. Result<_, E> where E is eyre::Report:

use eyre::WrapErr;
use lazy_errors::prelude::*;

fn parse(s: &str) -> eyre::Result<i32> {
    use core::str::FromStr;
    i32::from_str(s).wrap_err_with(|| format!("Not an i32: '{s}'"))
}

fn parse_all() -> eyre::Result<()> {
    let mut stash = ErrorStash::new(|| "Failed to parse");

    parse("πŸ™ˆ").or_stash(&mut stash);
    parse("πŸ™‰").or_stash(&mut stash);
    parse("πŸ™Š").or_stash(&mut stash);

    stash.into_eyre_result()
}

let err: eyre::Report = parse_all().unwrap_err();
let msg = format!("{err}");
assert!(msg.contains("πŸ™ˆ"));
assert!(msg.contains("πŸ™‰"));
assert!(msg.contains("πŸ™Š"));

Note: This method discards information because IntoEyreReport flattens the type into a single string that is then passed to eyre::eyre!.

In some cases, for example if you’re using or_create_stash, you may want to use IntoEyreReport instead.

ImplementorsΒ§

SourceΒ§

impl<F, M, I> IntoEyreResult<(), Error<I>> for ErrorStash<F, M, I>
where F: FnOnce() -> M, M: Display, Error<I>: IntoEyreReport,