use std::error::Error;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DiffError {
General(String),
PatchFailed(String),
UnsupportedOperation(String),
}
impl DiffError {
pub fn new(msg: impl Into<String>) -> Self {
Self::General(msg.into())
}
pub fn patch_failed(msg: impl Into<String>) -> Self {
Self::PatchFailed(msg.into())
}
pub fn unsupported(msg: impl Into<String>) -> Self {
Self::UnsupportedOperation(msg.into())
}
}
impl fmt::Display for DiffError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::General(msg) => write!(f, "{msg}"),
Self::PatchFailed(msg) => write!(f, "Patch failed: {msg}"),
Self::UnsupportedOperation(msg) => write!(f, "Unsupported operation: {msg}"),
}
}
}
impl Error for DiffError {}
impl From<String> for DiffError {
fn from(msg: String) -> Self {
Self::General(msg)
}
}
impl From<&str> for DiffError {
fn from(msg: &str) -> Self {
Self::General(msg.to_string())
}
}
pub type PatchError = DiffError;
pub type PatchFailedException = DiffError;