use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
use std::hash::Hash;
pub trait Kind:
Debug + Display + Clone + Copy + PartialEq + Eq + Hash + Default + Send + Sync + 'static
{
const RAW_KIND: Self;
const UNKNOWN_KIND: Self;
fn is_raw(&self) -> bool {
*self == Self::RAW_KIND
}
fn is_unknown(&self) -> bool {
*self == Self::UNKNOWN_KIND
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum DefaultErrorKind {
ValueValidation,
RuleViolation,
EntityAbsence,
InfrastructureFailure,
Raw,
#[default]
Unknown,
}
impl Display for DefaultErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let value = match self {
Self::ValueValidation => "ValueValidation",
Self::RuleViolation => "RuleViolation",
Self::EntityAbsence => "EntityAbsence",
Self::InfrastructureFailure => "InfrastructureFailure",
Self::Raw => "Raw",
Self::Unknown => "Unknown",
};
write!(f, "{value}")
}
}
impl Kind for DefaultErrorKind {
const RAW_KIND: Self = DefaultErrorKind::Raw;
const UNKNOWN_KIND: Self = DefaultErrorKind::Unknown;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum NoErrorKind {
#[default]
Anything,
}
impl Display for NoErrorKind {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
write!(f, "Anything")
}
}
impl Kind for NoErrorKind {
const RAW_KIND: Self = Self::Anything;
const UNKNOWN_KIND: Self = Self::Anything;
}