use std::fmt::{Display, Formatter};
#[derive(Debug)]
pub enum LocatorError {
NotFound { expected: &'static str },
Other(Box<dyn std::error::Error + Send + Sync + 'static>),
}
impl LocatorError {
pub fn not_found<T>() -> LocatorError {
LocatorError::NotFound {
expected: std::any::type_name::<T>(),
}
}
}
impl Display for LocatorError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
LocatorError::NotFound { expected } => {
write!(f, "unable to find `{}` in locator", expected)
}
LocatorError::Other(err) => err.fmt(f),
}
}
}
impl std::error::Error for LocatorError {}
impl From<Box<dyn std::error::Error + Send + Sync + 'static>> for LocatorError {
fn from(err: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
LocatorError::Other(err)
}
}