pub trait Diagnose<'s, T> {
type Error: Diagnostic;
// Required methods
fn diagnose(
self,
subject: impl Into<<Self::Error as Diagnostic>::Subject>,
) -> Result<T, Report<Self::Error>>;
fn diagnose_with<F, S>(self, f: F) -> Result<T, Report<Self::Error>>
where F: FnOnce() -> S,
S: Into<<Self::Error as Diagnostic>::Subject>;
}
Expand description
An extension trait for Result<_, E>
, where E
is an implementation of
Diagnostic
, that converts E
into Report<E>
, yielding
Result<_, Report<E>>
.
Required Associated Types§
Sourcetype Error: Diagnostic
type Error: Diagnostic
The error type returned from diagnose
and diagnose_with
.
Required Methods§
Sourcefn diagnose(
self,
subject: impl Into<<Self::Error as Diagnostic>::Subject>,
) -> Result<T, Report<Self::Error>>
fn diagnose( self, subject: impl Into<<Self::Error as Diagnostic>::Subject>, ) -> Result<T, Report<Self::Error>>
If the Result
is an Err
, converts the error into a Report
with
the supplied subject
.
§Example
use core::any::{Any, TypeId};
use jsonptr::{Pointer, ParseError, Diagnose, Report};
let subj = "invalid/pointer";
let err = Pointer::parse(subj).diagnose(subj).unwrap_err();
assert_eq!(err.type_id(),TypeId::of::<Report<ParseError>>());
Sourcefn diagnose_with<F, S>(self, f: F) -> Result<T, Report<Self::Error>>
fn diagnose_with<F, S>(self, f: F) -> Result<T, Report<Self::Error>>
If the Result
is an Err
, converts the error into a Report
with
the subject returned from f
§Example
use core::any::{Any, TypeId};
use jsonptr::{Pointer, ParseError, Diagnose, Report};
let subj = "invalid/pointer";
let err = Pointer::parse(subj).diagnose_with(|| subj).unwrap_err();
assert_eq!(err.type_id(),TypeId::of::<Report<ParseError>>());
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.