use std::fmt;
#[derive(Debug)]
pub enum SaveError {
CreatingFile {
filename: String,
source: std::io::Error,
},
WritingFile {
filename: String,
source: bincode::Error,
},
}
impl fmt::Display for SaveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::CreatingFile { filename, source } => {
write!(f, "Failed to open file {}: {}", filename, source)
}
Self::WritingFile { filename, source } => {
write!(f, "Failed to write file {}: {}", filename, source)
}
}
}
}
impl std::error::Error for SaveError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::CreatingFile { source, .. } => Some(source),
Self::WritingFile { source, .. } => Some(source),
}
}
}
#[derive(Debug)]
pub enum LoadError {
OpeningFile {
filename: String,
source: std::io::Error,
},
ReadingFile {
filename: String,
source: bincode::Error,
},
}
impl fmt::Display for LoadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::OpeningFile { filename, source } => {
write!(f, "Failed to open file {}: {}", filename, source)
}
Self::ReadingFile { filename, source } => {
write!(f, "Failed to read file {}: {}", filename, source)
}
}
}
}
impl std::error::Error for LoadError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::OpeningFile { source, .. } => Some(source),
Self::ReadingFile { source, .. } => Some(source),
}
}
}