pub type Error = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug)]
pub struct NotFound;
impl std::fmt::Display for NotFound {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Not found")
}
}
impl std::error::Error for NotFound {}
impl NotFound {
pub fn is_not_found(err: &Error) -> bool {
err.downcast_ref::<NotFound>().is_some()
}
}
pub fn has_not_found_io_error(err: &Error) -> bool {
if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
return io_err.kind() == std::io::ErrorKind::NotFound;
}
let mut source = err.source();
while let Some(err) = source {
if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
if io_err.kind() == std::io::ErrorKind::NotFound {
return true;
}
}
source = err.source();
}
false
}