box_format/path/
error.rs

1use std::fmt;
2
3#[derive(Debug, Clone)]
4pub enum IntoBoxPathError {
5    UnrepresentableStr,
6    NonCanonical,
7    EmptyPath,
8}
9
10impl std::error::Error for IntoBoxPathError {}
11
12impl fmt::Display for IntoBoxPathError {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(f, "{}", self.as_str())
15    }
16}
17
18impl IntoBoxPathError {
19    pub fn as_str(&self) -> &str {
20        match self {
21            IntoBoxPathError::NonCanonical => "non-canonical path received as input",
22            IntoBoxPathError::UnrepresentableStr => "unrepresentable string found in path",
23            IntoBoxPathError::EmptyPath => "no path provided",
24        }
25    }
26
27    pub fn as_io_error(&self) -> std::io::Error {
28        use std::io::{Error, ErrorKind};
29        Error::new(ErrorKind::InvalidInput, self.as_str())
30    }
31}