diff_trees/error/
strip_prefix.rs

1use std::fmt::Display;
2use std::path::Path;
3use std::path::PathBuf;
4
5/// An error encountered while removing a prefix from a [`Path`].
6#[derive(Debug)]
7pub struct StripPrefixError {
8    pub(crate) path: PathBuf,
9    pub(crate) prefix: PathBuf,
10}
11
12impl StripPrefixError {
13    /// The path that caused this error.
14    pub fn path(&self) -> &Path {
15        &self.path
16    }
17
18    /// The prefix that the path was expected to have.
19    pub fn prefix(&self) -> &Path {
20        &self.prefix
21    }
22}
23
24impl Display for StripPrefixError {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(
27            f,
28            "Path does not have prefix {}: {}",
29            self.prefix.display(),
30            self.path.display(),
31        )
32    }
33}
34
35impl std::error::Error for StripPrefixError {}