diff_trees/error/
hash.rs

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