[][src]Struct describe_err::Described

pub struct Described<E: Error + 'static> { /* fields omitted */ }

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

impl<E> Send for Described<E> where
    E: Send

impl<E> Sync for Described<E> where
    E: Sync

impl<E> Unpin for Described<E> where
    E: Unpin

impl<E> UnwindSafe for Described<E> where
    E: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.