#[derive(ErrorKind)]
{
// Attributes available to this derive:
#[error_kind]
}
Expand description
Create a kind method for struct
ยงExamples
use derive_error_kind::ErrorKind;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum ErrorType {
A,
B,
C,
}
#[derive(ErrorKind)]
#[error_kind(ErrorType)]
enum CacheError {
#[error_kind(ErrorType, A)]
Poisoned,
#[error_kind(ErrorType, B)]
Missing,
}
#[derive(ErrorKind)]
#[error_kind(ErrorType)]
enum ServiceError {
#[error_kind(transparent)]
Cache(CacheError),
#[error_kind(ErrorType, C)]
Db,
}
assert_eq!(ServiceError::Cache(CacheError::Missing).kind(), ErrorType::B);
assert_eq!(ServiceError::Db.kind(), ErrorType::C);