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Β§
Sourcefn into_eyre_result(self) -> Result<T, Report>
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.