pub struct AppErr(/* private fields */);Expand description
An error type used to pass an application-specific error through a library runtime.
Application callbacks can return this type for the Err() case in order
to allow application-defined errors to be passed back to the application
through a library runtime.
Implementations§
Source§impl AppErr
impl AppErr
Sourcepub fn new<E>(e: E) -> Self
pub fn new<E>(e: E) -> Self
Create a new application callback error object that can be converted back
into to its original type (as long as it is Any compatible).
use std::fmt;
use apperr::{AppErr, Blessed};
#[derive(Debug)]
enum MyErr {
Something(String)
}
impl fmt::Display for MyErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MyErr::Something(s) => {
write!(f, "Some error; {}", s)
}
}
}
}
impl std::error::Error for MyErr { }
impl Blessed for MyErr { }
let apperr = AppErr::new(MyErr::Something("hello".into()));Sourcepub fn is<T>(&self) -> boolwhere
T: Any,
pub fn is<T>(&self) -> boolwhere
T: Any,
Inspect error type wrapped by the AppErr.
use std::fmt;
use apperr::{AppErr, Blessed};
#[derive(Debug)]
enum MyErr {
Something(String)
}
impl fmt::Display for MyErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MyErr::Something(s) => {
write!(f, "Some error; {}", s)
}
}
}
}
impl std::error::Error for MyErr { }
impl Blessed for MyErr { }
let apperr = AppErr::new(MyErr::Something("hello".into()));
assert!(apperr.is::<MyErr>());
assert_eq!(apperr.is::<String>(), false);Sourcepub fn try_into_inner<E: 'static>(self) -> Result<E, AppErr>
pub fn try_into_inner<E: 'static>(self) -> Result<E, AppErr>
Attempt to unpack and cast the inner error type.
If it can’t be downcast to E, the AppErr will be returned back to the
caller in the Err() case.
use std::fmt;
use apperr::{AppErr, Blessed};
#[derive(Debug)]
enum MyErr {
Something(String)
}
impl fmt::Display for MyErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MyErr::Something(s) => {
write!(f, "Some error; {}", s)
}
}
}
}
impl std::error::Error for MyErr { }
impl Blessed for MyErr { }
let apperr = AppErr::new(MyErr::Something("hello".into()));
let Ok(e) = apperr.try_into_inner::<MyErr>() else {
panic!("Unexpectedly not MyErr");
};Sourcepub fn unwrap_inner<E: 'static>(self) -> E
pub fn unwrap_inner<E: 'static>(self) -> E
Unwrap application-specific error.
use std::fmt;
use apperr::{AppErr, Blessed};
#[derive(Debug)]
enum MyErr {
Something(String)
}
impl fmt::Display for MyErr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
MyErr::Something(s) => {
write!(f, "Some error; {}", s)
}
}
}
}
impl std::error::Error for MyErr { }
impl Blessed for MyErr { }
let apperr = AppErr::new(MyErr::Something("hello".into()));
let MyErr::Something(e) = apperr.unwrap_inner::<MyErr>() else {
panic!("Unexpectedly not MyErr::Something");
};
assert_eq!(e, "hello");§Panic
Panics if the inner type is not castable to E.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AppErr
impl !RefUnwindSafe for AppErr
impl Send for AppErr
impl !Sync for AppErr
impl Unpin for AppErr
impl !UnwindSafe for AppErr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more