Skip to main content

Diagnose

Trait Diagnose 

Source
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§

Source

type Error: Diagnostic

The error type returned from diagnose and diagnose_with.

Required Methods§

Source

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>>());
Source

fn diagnose_with<F, S>(self, f: F) -> Result<T, Report<Self::Error>>
where F: FnOnce() -> S, S: Into<<Self::Error as Diagnostic>::Subject>,

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".

Implementations on Foreign Types§

Source§

impl<T, E> Diagnose<'_, T> for Result<T, E>
where E: Diagnostic,

Source§

type Error = E

Source§

fn diagnose( self, subject: impl Into<<Self::Error as Diagnostic>::Subject>, ) -> Result<T, Report<Self::Error>>

Source§

fn diagnose_with<F, S>(self, f: F) -> Result<T, Report<Self::Error>>
where F: FnOnce() -> S, S: Into<<Self::Error as Diagnostic>::Subject>,

Implementors§