pub trait ResultExt<T, E>: Sized {
// Required methods
fn widen<E2>(self) -> Result<T, E2>
where Self: WidenResult<T, E2>;
fn narrow_rejected(self) -> Result<T, <E as NarrowRejectedLane>::Narrowed>
where E: NarrowRejectedLane;
fn narrow_transient(
self,
attempts: u32,
) -> Result<T, <E as Laned>::WithoutTransient>
where E: Laned;
fn narrow_denied(self) -> Result<T, <E as NarrowDeniedLane>::Narrowed>
where E: NarrowDeniedLane;
fn classify<W>(self) -> Result<T, W>
where W: Classify + From<E>;
}Expand description
The one trait a consumer imports to move a Result between error
signatures: widen it to a bigger profile, narrow away a lane that is no
longer live at this boundary, classify a foreign error into a local
wrapper, or (under tracing) record it onto the current span.
Required Methods§
Sourcefn widen<E2>(self) -> Result<T, E2>where
Self: WidenResult<T, E2>,
fn widen<E2>(self) -> Result<T, E2>where
Self: WidenResult<T, E2>,
Target-inferred widening for Fault or Fail results.
Fault results widen to Fault; Fail results widen to Fail,
converting the rejection through crate::Lift. Success values and
fault payloads are preserved. Widening can add lanes, but cannot
silently discard an enabled lane:
use errlanes::{Fault, ResultExt, lanes};
fn discard_denied(value: Result<(), Fault<lanes!(Denied, Fatal)>>)
-> Result<(), Fault<lanes!(Fatal)>>
{
value.widen()
}Sourcefn narrow_rejected(self) -> Result<T, <E as NarrowRejectedLane>::Narrowed>where
E: NarrowRejectedLane,
fn narrow_rejected(self) -> Result<T, <E as NarrowRejectedLane>::Narrowed>where
E: NarrowRejectedLane,
Narrows away the Rejected lane: a rejection with no caller left to
correct it becomes Fatal(Invariant), carrying the rejection as its
source. Only available where E is a Fail — a Fault has no
rejected lane to narrow, and that is a compile error, not an
identity:
use errlanes::{Fault, ResultExt, lanes};
fn narrow(value: Result<(), Fault<lanes!(Fatal)>>)
-> Result<(), Fault<lanes!(Fatal)>>
{
value.narrow_rejected()
}Sourcefn narrow_transient(
self,
attempts: u32,
) -> Result<T, <E as Laned>::WithoutTransient>where
E: Laned,
fn narrow_transient(
self,
attempts: u32,
) -> Result<T, <E as Laned>::WithoutTransient>where
E: Laned,
Narrows away the Transient lane: a caller-owned retry loop hands
back the narrowed profile once it stops retrying, so it stops
offering Transient to its own callers. attempts is what the loop
counted; an exhausted transient becomes Fatal(Exhausted) with the
last transient as its source.
Sourcefn narrow_denied(self) -> Result<T, <E as NarrowDeniedLane>::Narrowed>where
E: NarrowDeniedLane,
fn narrow_denied(self) -> Result<T, <E as NarrowDeniedLane>::Narrowed>where
E: NarrowDeniedLane,
Narrows away the Denied lane: a denial at a boundary with no
subject (code running as the system) becomes Fatal(Denied). Only
available where E’s profile enables Denied:
use errlanes::{Fault, ResultExt, lanes};
fn narrow(value: Result<(), Fault<lanes!(Transient, Fatal)>>)
-> Result<(), Fault<lanes!(Transient, Fatal)>>
{
value.narrow_denied()
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".