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§
Sourcetype Kind: EvitableErrorKind
type Kind: EvitableErrorKind
Associated error kind enum.
Sourcetype Error: EvitableError<Context = Self, Kind = Self::Kind>
type Error: EvitableError<Context = Self, Kind = Self::Kind>
Associated error struct.
Required Methods§
Sourcefn kind(&self) -> Self::Kind
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§
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.