#[derive(Debug)]
pub enum Error {
ValueNotFoundAtPath(String),
AsCastFailed(String),
DeserializationFailed(Box<dyn std::error::Error>),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use Error;
match self {
Error::ValueNotFoundAtPath(path) => {
write!(f, "value not found at the path: {}", path)
}
Error::AsCastFailed(conv_name) => {
write!(f, "casting with {}() failed", conv_name)
}
Error::DeserializationFailed(err) => {
write!(f, "failed to deserialize the queried value: {}", err)
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use Error;
match self {
Error::DeserializationFailed(err) => Some(err.as_ref()),
_ => None,
}
}
}
pub type Result<T> = std::result::Result<T, Error>;