1pub type Error = Box<dyn std::error::Error + Send + Sync>;
2
3#[derive(Debug)]
4pub struct NotFound;
5
6impl std::fmt::Display for NotFound {
7 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8 write!(f, "Not found")
9 }
10}
11
12impl std::error::Error for NotFound {}
13
14impl NotFound {
15 pub fn is_not_found(err: &Error) -> bool {
17 err.downcast_ref::<NotFound>().is_some()
18 }
19}
20
21pub fn has_not_found_io_error(err: &Error) -> bool {
23 if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
25 return io_err.kind() == std::io::ErrorKind::NotFound;
26 }
27
28 let mut source = err.source();
30 while let Some(err) = source {
31 if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
32 if io_err.kind() == std::io::ErrorKind::NotFound {
33 return true;
34 }
35 }
36 source = err.source();
37 }
38
39 false
40}