use std::convert::Infallible;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Fallout {
Untouched,
InDoubt,
}
impl Fallout {
pub fn is_in_doubt(self) -> bool {
matches!(self, Self::InDoubt)
}
}
pub trait ProcessError: 'static {
fn fallout(&self) -> Fallout;
}
impl ProcessError for Infallible {
fn fallout(&self) -> Fallout {
match *self {}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[derive(Debug)]
enum StoreError {
Refused,
CommitTimedOut,
}
impl ProcessError for StoreError {
fn fallout(&self) -> Fallout {
match self {
Self::Refused => Fallout::Untouched,
Self::CommitTimedOut => Fallout::InDoubt,
}
}
}
#[test]
fn a_domain_error_classifies_itself() {
assert_eq!(StoreError::Refused.fallout(), Fallout::Untouched);
assert!(!StoreError::Refused.fallout().is_in_doubt());
assert_eq!(StoreError::CommitTimedOut.fallout(), Fallout::InDoubt);
assert!(StoreError::CommitTimedOut.fallout().is_in_doubt());
}
}