Skip to main content

ApiErrorKind

Trait ApiErrorKind 

Source
pub trait ApiErrorKind:
    Sized
    + Copy
    + Clone
    + Default
    + Eq
    + PartialEq
    + Debug
    + Display
    + ToHttpStatus
    + From<CommonErrorKind>
    + From<u16>
    + 'static {
    const KINDS: &'static [Self];

    // Required methods
    fn is_unknown(&self) -> bool;
    fn to_name(self) -> &'static str;
    fn to_msg(self) -> &'static str;
    fn to_code(self) -> u16;
    fn from_code(code: u16) -> Self;
}
Expand description

ApiErrorKind defines the methods required of all API error kinds. Implementations of this trait are derived by api_error_kind!.

Try to keep this light, since debugging macros is a pain : )

Required Associated Constants§

Source

const KINDS: &'static [Self]

An array of all known error kind variants, excluding Unknown(_).

Required Methods§

Source

fn is_unknown(&self) -> bool

Returns true if the error kind is unrecognized (at least by this version of the software).

Source

fn to_name(self) -> &'static str

Returns the variant name of this error kind.

Ex: MyErrorKind::Foo.to_name() == "Foo"

Source

fn to_msg(self) -> &'static str

Returns the human-readable message for this error kind. For a generated error kind, this is the same as the variant’s doc string.

Source

fn to_code(self) -> u16

Returns the serializable ErrorCode for this error kind.

Source

fn from_code(code: u16) -> Self

Returns the error kind for this raw ErrorCode.

This method is infallible as every error kind must always have an Unknown(_) variant for backwards compatibility.

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§