devela::_dep::rkyv::bytecheck::rancor

Trait Source

pub trait Source: Trace + Error {
    // Required method
    fn new<T>(source: T) -> Self
       where T: Error + Send + Sync + 'static;
}
Available on crate feature dep_rkyv only.
Expand description

An error type which can be uniformly constructed from an Error and additional trace information.

§Example

use core::{error::Error, fmt};

use rancor::{fail, Source};

#[derive(Debug)]
struct DivideByZeroError;

impl fmt::Display for DivideByZeroError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "attempted to divide by zero")
    }
}

impl Error for DivideByZeroError {}

fn try_divide<E: Source>(a: i32, b: i32) -> Result<i32, E> {
    if b == 0 {
        fail!(DivideByZeroError);
    }
    Ok(a / b)
}

Required Methods§

fn new<T>(source: T) -> Self
where T: Error + Send + Sync + 'static,

Returns a new Self using the given Error.

Depending on the specific implementation, this may box the error, immediately emit a diagnostic, or discard it and only remember that some error occurred.

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.

Implementors§

§

impl Source for Panic

§

impl Source for BoxedError

§

impl Source for Error

§

impl Source for Failure