diff_trees/error/
metadata.rs

1use std::fmt::Display;
2use std::path::Path;
3use std::path::PathBuf;
4
5/// An error encountered while accessing a [`Path`]'s [`Path::metadata`].
6#[derive(Debug)]
7pub struct MetadataError {
8    pub(crate) path: PathBuf,
9    pub(crate) inner: std::io::Error,
10}
11
12impl MetadataError {
13    /// The path that caused this error.
14    pub fn path(&self) -> &Path {
15        &self.path
16    }
17}
18
19impl Display for MetadataError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        write!(
22            f,
23            "Failed to query metadata for `{}`: {}",
24            self.path.display(),
25            self.inner
26        )
27    }
28}
29
30impl std::error::Error for MetadataError {
31    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
32        Some(&self.inner)
33    }
34}