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
use std::fmt; #[derive(Debug, Clone)] pub enum IntoBoxPathError { UnrepresentableStr, NonCanonical, EmptyPath, } impl std::error::Error for IntoBoxPathError {} impl fmt::Display for IntoBoxPathError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.as_str()) } } impl IntoBoxPathError { pub fn as_str(&self) -> &str { match self { IntoBoxPathError::NonCanonical => "non-canonical path received as input", IntoBoxPathError::UnrepresentableStr => "unrepresentable string found in path", IntoBoxPathError::EmptyPath => "no path provided", } } pub fn as_io_error(&self) -> std::io::Error { use std::io::{Error, ErrorKind}; Error::new(ErrorKind::InvalidInput, self.as_str()) } }