#[derive(Debug)]
pub enum MosaicError {
Io(std::io::Error),
Serialize(String),
Deserialize(String),
VersionMismatch { expected: String, found: String },
}
impl std::fmt::Display for MosaicError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Io(error) => write!(formatter, "IO error: {error}"),
Self::Serialize(message) => write!(formatter, "Serialization error: {message}"),
Self::Deserialize(message) => write!(formatter, "Deserialization error: {message}"),
Self::VersionMismatch { expected, found } => {
write!(
formatter,
"Version mismatch: expected '{expected}', found '{found}'"
)
}
}
}
}
impl std::error::Error for MosaicError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(error) => Some(error),
_ => None,
}
}
}
impl From<std::io::Error> for MosaicError {
fn from(error: std::io::Error) -> Self {
Self::Io(error)
}
}