use std::fmt;
#[derive(Debug)]
pub enum InfError {
Io(std::io::Error),
Parse {
line: usize,
message: String,
},
UnmatchedBlock {
line: usize,
block_type: String,
},
}
impl fmt::Display for InfError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(e) => write!(f, "IO error: {e}"),
Self::Parse { line, message } => {
write!(f, "Parse error at line {line}: {message}")
}
Self::UnmatchedBlock { line, block_type } => {
write!(
f,
"Unmatched {block_type}=start/end block starting at line {line}"
)
}
}
}
}
impl std::error::Error for InfError {}
impl From<std::io::Error> for InfError {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
pub type InfResult<T> = Result<T, InfError>;