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§
sourcefn source(&self) -> Option<&(dyn ErrorTrait + 'static)>
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
impl dyn ErrorTrait
sourcepub fn is<T>(&self) -> boolwhere
T: ErrorTrait + 'static,
pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,
Returns true
if the boxed type is the same as T
sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ErrorTrait + 'static,
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.
sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: ErrorTrait + 'static,
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
impl dyn ErrorTrait + Send
sourcepub fn is<T>(&self) -> boolwhere
T: ErrorTrait + 'static,
pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,
Forwards to the method defined on the type dyn ErrorTrait
.
sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ErrorTrait + 'static,
pub fn downcast_ref<T>(&self) -> Option<&T>where T: ErrorTrait + 'static,
Forwards to the method defined on the type dyn ErrorTrait
.
sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: ErrorTrait + 'static,
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
impl dyn ErrorTrait + Send + Sync
sourcepub fn is<T>(&self) -> boolwhere
T: ErrorTrait + 'static,
pub fn is<T>(&self) -> boolwhere T: ErrorTrait + 'static,
Forwards to the method defined on the type dyn ErrorTrait
.
sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: ErrorTrait + 'static,
pub fn downcast_ref<T>(&self) -> Option<&T>where T: ErrorTrait + 'static,
Forwards to the method defined on the type dyn ErrorTrait
.
sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: ErrorTrait + 'static,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where T: ErrorTrait + 'static,
Forwards to the method defined on the type dyn ErrorTrait
.