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