use core::fmt;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum Error {
Parse {
expr: String,
pos: usize,
msg: String,
},
UnknownVariable(String),
Invalid(String),
Format(String),
Io(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Parse { expr, pos, msg } => {
write!(f, "cannot parse expression {expr:?} at offset {pos}: {msg}")
}
Error::UnknownVariable(v) => write!(f, "unknown variable or parameter {v:?}"),
Error::Invalid(m) => write!(f, "invalid value: {m}"),
Error::Format(m) => write!(f, "format error: {m}"),
Error::Io(m) => write!(f, "I/O error: {m}"),
}
}
}
impl std::error::Error for Error {}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e.to_string())
}
}
pub type Result<T, E = Error> = core::result::Result<T, E>;