1pub type Error = Box<dyn std::error::Error + Send + Sync>;
10
11#[derive(Debug)]
13pub struct NotFound;
14
15impl std::fmt::Display for NotFound {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 write!(f, "Not found")
18 }
19}
20
21impl std::error::Error for NotFound {}
22
23impl NotFound {
24 pub fn is_not_found(err: &Error) -> bool {
26 err.downcast_ref::<NotFound>().is_some()
27 }
28}
29
30pub fn has_not_found_io_error(err: &Error) -> bool {
32 if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
34 return io_err.kind() == std::io::ErrorKind::NotFound;
35 }
36
37 let mut source = err.source();
39 while let Some(err) = source {
40 if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
41 if io_err.kind() == std::io::ErrorKind::NotFound {
42 return true;
43 }
44 }
45 source = err.source();
46 }
47
48 false
49}