[][src]Trait evitable::ErrorContext

pub trait ErrorContext: Display + Debug + Sized + 'static {
    type Kind: EvitableErrorKind;
    type Error: EvitableError<Context = Self, Kind = Self::Kind>;
    fn kind(&self) -> Self::Kind;

    fn into_error<S: StdError + 'static>(self, source: S) -> Self::Error { ... }
}

Error context trait, typically used with #[derive(ErrorContext)]. This produces Error and ErrorKind types for the given context.

Associated Types

type Kind: EvitableErrorKind

Associated error kind enum.

type Error: EvitableError<Context = Self, Kind = Self::Kind>

Associated error struct.

Loading content...

Required methods

fn kind(&self) -> Self::Kind

Get the error kind.

Example

 #[derive(ErrorContext)]
 pub enum Context {
   #[evitable(description("Io error ({})", 0))]
   Io(u8),

   #[evitable(description = "Fmt error")]
   Fmt,
 }

 // Later
 let error = Context::Io(42);
 let t =
   match error.kind() {
     evitable_context::ErrorKind::Io => "Io",
     evitable_context::ErrorKind::Fmt => "Fmt",
     _ => "Other",
   };

 assert_eq!(t, "Io");
Loading content...

Provided methods

fn into_error<S: StdError + 'static>(self, source: S) -> Self::Error

Convert the current context into an error.

Arguments

  • source - Error source

Example

 #[derive(ErrorContext)]
 #[evitable(description = "Error")]
 pub struct Context(u8);

 // Later
 let io_error = io::Error::from(io::ErrorKind::NotFound);
 let error = Context(42).into_error(io_error);
Loading content...

Implementors

Loading content...