mm1_common/errors/
error_kind.rs1use std::fmt;
2
3use crate::types::Never;
4
5pub trait HasErrorKind<Kind: ErrorKind> {
6 fn kind(&self) -> Kind;
7}
8
9pub trait ErrorKind: fmt::Display + Eq + Ord + Copy + Send + Sync + 'static {}
10
11impl<AnyKind> HasErrorKind<AnyKind> for Never
12where
13 AnyKind: ErrorKind,
14{
15 fn kind(&self) -> AnyKind {
16 match *self {}
17 }
18}
19
20impl<K> ErrorKind for K where K: fmt::Display + Eq + Ord + Copy + Send + Sync + 'static {}
21
22#[macro_export]
23macro_rules! impl_error_kind {
24 ($ty:ty) => {
25 impl std::fmt::Display for $ty {
26 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27 std::fmt::Debug::fmt(self, f)
28 }
29 }
30 impl std::error::Error for $ty {}
31 impl $crate::errors::error_kind::HasErrorKind<Self> for $ty {
32 fn kind(&self) -> Self {
33 *self
34 }
35 }
36 };
37}