1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! The error types defined by this crate.

use std::error::Error;
use std::fmt;
use std::fmt::Display;
use std::fmt::Formatter;
use std::path::Path;
use std::path::PathBuf;

/// The error returned when [`BasePath::try_new`] is given a path without a
/// prefix.
///
/// [`BasePath::try_new`]: super::BasePath::try_new
#[derive(Debug, PartialEq)]
pub struct MissingPrefixError(pub(super) ());

impl Display for MissingPrefixError {
    #[inline]
    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
        "normpath: path is missing a prefix".fmt(formatter)
    }
}

impl Error for MissingPrefixError {}

/// The error returned when [`BasePathBuf::try_new`] is given a path without a
/// prefix.
///
/// [`BasePathBuf::try_new`]: super::BasePathBuf::try_new
#[derive(Debug, PartialEq)]
pub struct MissingPrefixBufError(pub(super) PathBuf);

impl MissingPrefixBufError {
    /// Returns a reference to the path that caused this error.
    #[inline]
    #[must_use]
    pub fn as_path(&self) -> &Path {
        &self.0
    }

    /// Returns the path that caused this error.
    #[inline]
    #[must_use]
    pub fn into_path_buf(self) -> PathBuf {
        self.0
    }
}

impl Display for MissingPrefixBufError {
    #[inline]
    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
        write!(
            formatter,
            "normpath: path is missing a prefix: {}",
            self.0.display(),
        )
    }
}

impl Error for MissingPrefixBufError {}

/// The error returned when [`BasePath::parent`] cannot remove the path's last
/// component.
///
/// [`BasePath::parent`]: super::BasePath::parent
#[derive(Debug, PartialEq)]
pub struct ParentError(pub(super) ());

impl Display for ParentError {
    #[inline]
    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
        "normpath: cannot remove the path's last component".fmt(formatter)
    }
}

impl Error for ParentError {}