ErrorContext

Trait ErrorContext 

Source
pub trait ErrorContext:
    Display
    + Debug
    + Sized
    + Send
    + Sync
    + 'static {
    type Kind: EvitableErrorKind;
    type Error: EvitableError<Context = Self, Kind = Self::Kind>;

    // Required method
    fn kind(&self) -> Self::Kind;

    // Provided method
    fn into_error<S: StdError + Send + Sync + 'static>(
        self,
        source: S,
    ) -> Self::Error { ... }
}
Expand description

Error context trait, typically used with #[evitable]. This produces Error and ErrorKind types for the given context.

Required Associated Types§

Source

type Kind: EvitableErrorKind

Associated error kind enum.

Source

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

Associated error struct.

Required Methods§

Source

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

Get the error kind.

§Example
 #[evitable]
 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");

Provided Methods§

Source

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

Convert the current context into an error.

§Arguments
  • source - Error source
§Example
 #[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);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§