Trait tardar::DiagnosticResultExt
source · pub trait DiagnosticResultExt<'d, T> {
// Required methods
fn ok_output(self) -> Option<T>;
fn diagnostics(&self) -> &[BoxedDiagnostic<'d>];
fn map_output<U, F>(self, f: F) -> DiagnosticResult<'d, U>
where F: FnOnce(T) -> U;
fn and_then_diagnose<U, F>(self, f: F) -> DiagnosticResult<'d, U>
where F: FnOnce(T) -> DiagnosticResult<'d, U>;
}
Expand description
Extension methods for DiagnosticResult
s.
Required Methods§
sourcefn ok_output(self) -> Option<T>
fn ok_output(self) -> Option<T>
Converts from DiagnosticResult<'_, T>
into Option<T>
.
This function is similar to Result::ok
, but gets only the non-diagnostic output T
from the Ok
variant in DiagnosticResult
, discarding diagnostics.
sourcefn diagnostics(&self) -> &[BoxedDiagnostic<'d>]
fn diagnostics(&self) -> &[BoxedDiagnostic<'d>]
Gets the Diagnostic
s associated with the DiagnosticResult
.
Both the success and failure case may include diagnostics.
sourcefn map_output<U, F>(self, f: F) -> DiagnosticResult<'d, U>where
F: FnOnce(T) -> U,
fn map_output<U, F>(self, f: F) -> DiagnosticResult<'d, U>where F: FnOnce(T) -> U,
Maps DiagnosticResult<'d, T>
into DiagnosticResult<'d, U>
by applying a function over
the non-diagnostic output of the Ok
variant.
This function is similar to Result::map
, but maps only the non-diagnostic output T
from the Ok
variant in DiagnosticResult
, ignoring diagnostics.
sourcefn and_then_diagnose<U, F>(self, f: F) -> DiagnosticResult<'d, U>where
F: FnOnce(T) -> DiagnosticResult<'d, U>,
fn and_then_diagnose<U, F>(self, f: F) -> DiagnosticResult<'d, U>where F: FnOnce(T) -> DiagnosticResult<'d, U>,
Calls the given function if the DiagnosticResult
is Ok
and otherwise returns the Err
variant of the DiagnosticResult
.
This function is similar to Result::and_then
, but additionally forwards and collects
diagnostics.