pub type Failure = String;
#[derive(Clone, Debug, PartialEq, Eq, derive_more::From)]
pub enum ContrafactError {
Other(String),
}
pub type ContrafactResult<T> = Result<T, ContrafactError>;
#[derive(Clone, Debug, derive_more::From)]
pub enum MutationError {
Check(Failure),
#[from]
Arbitrary(arbitrary::Error),
#[from]
Internal(ContrafactError),
User(String),
}
impl PartialEq for MutationError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Check(s), Self::Check(o)) => s == o,
(Self::Arbitrary(s), Self::Arbitrary(o)) => s.to_string() == o.to_string(),
(Self::Internal(s), Self::Internal(o)) => s == o,
(Self::User(s), Self::User(o)) => s == o,
_ => false,
}
}
}
pub type Mutation<T> = Result<T, MutationError>;
pub trait MutationExt<T> {
fn map_check_err(self, f: impl Fn(Failure) -> Failure) -> Mutation<T>;
}
impl<T> MutationExt<T> for Mutation<T> {
fn map_check_err(self, f: impl Fn(Failure) -> Failure) -> Mutation<T> {
match self {
Err(MutationError::Check(e)) => Err(MutationError::Check(f(e))),
other => other,
}
}
}