Trait eos_rs::api::io::ErrorTrait

source ·
pub trait ErrorTrait: Debug + Display {
    // Provided method
    fn source(&self) -> Option<&(dyn ErrorTrait + 'static)> { ... }
}
Expand description

A trait providing a subset of std::error::Error’s functionality.

Provided Methods§

source

fn source(&self) -> Option<&(dyn ErrorTrait + 'static)>

The lower-level source of this error, if any.

Examples
use core::fmt;
use acid_io::ErrorTrait;

#[derive(Debug)]
struct SuperError {
    side: SuperErrorSideKick,
}

impl fmt::Display for SuperError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "SuperError is here!")
    }
}

impl ErrorTrait for SuperError {
    fn source(&self) -> Option<&(dyn ErrorTrait + 'static)> {
        Some(&self.side)
    }
}

#[derive(Debug)]
struct SuperErrorSideKick;

impl fmt::Display for SuperErrorSideKick {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "SuperErrorSideKick is here!")
    }
}

impl ErrorTrait for SuperErrorSideKick {}

fn get_super_error() -> Result<(), SuperError> {
    Err(SuperError { side: SuperErrorSideKick })
}

fn main() {
    match get_super_error() {
        Err(e) => {
            println!("Error: {}", e);
            println!("Caused by: {}", e.source().unwrap());
        }
        _ => println!("No error"),
    }
}

Implementations§

source§

impl dyn ErrorTrait

source

pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,

Returns true if the boxed type is the same as T

source

pub fn downcast_ref<T>(&self) -> Option<&T>where T: ErrorTrait + 'static,

Returns some reference to the boxed value if it is of type T, or None if it isn’t.

source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: ErrorTrait + 'static,

Returns some mutable reference to the boxed value if it is of type T, or None if it isn’t.

source§

impl dyn ErrorTrait + Send

source

pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

source

pub fn downcast_ref<T>(&self) -> Option<&T>where T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

source§

impl dyn ErrorTrait + Send + Sync

source

pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

source

pub fn downcast_ref<T>(&self) -> Option<&T>where T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: ErrorTrait + 'static,

Forwards to the method defined on the type dyn ErrorTrait.

Implementors§