[−][src]Struct describe_err::Described
An error wrapper with description.
This struct can hold every error, with the only restriction that this error
must be 'static
to support downcasting through source
.
When converting this wrapper to string with Display
, it will render colon-separated
pair of description and original error:
use describe_err::{Described, describing}; fn fmt<E: std::error::Error + 'static>(err: &Described<E>) -> String { format!("{}: {}", err.description(), err.original()) } fn main() { // Let's create a simple error with auto-generated description... let res: Result<u32, _> = describing!("Not a number".parse()); // ...then unwrap it... let err = res.unwrap_err(); // and see that the formatting is indeed the same: assert_eq!(fmt(&err), format!("{}", err)); }
Implementations
impl<E: Error + 'static> Described<E>
[src]
pub fn description(&self) -> &str
[src]
Directly retrieves an error description.
pub fn original(&self) -> &E
[src]
Directly retrieves an original error.
This method is different from source
,
since it is generic and is known to return exactly the wrapped type,
not a boxed trait object. This way you won't need any downcasting.
Trait Implementations
impl<E: Debug + Error + 'static> Debug for Described<E>
[src]
impl<E: Error + 'static> Display for Described<E>
[src]
impl<E: Error + 'static> Error for Described<E>
[src]
Auto Trait Implementations
impl<E> RefUnwindSafe for Described<E> where
E: RefUnwindSafe,
E: RefUnwindSafe,
impl<E> Send for Described<E> where
E: Send,
E: Send,
impl<E> Sync for Described<E> where
E: Sync,
E: Sync,
impl<E> Unpin for Described<E> where
E: Unpin,
E: Unpin,
impl<E> UnwindSafe for Described<E> where
E: UnwindSafe,
E: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,