use std::fmt;
#[derive(Debug)]
pub struct Error {
kind: ErrorKind,
}
impl Error {
fn new(kind: ErrorKind) -> Self {
Error { kind }
}
pub(crate) fn empty_path() -> Self {
Error::new(ErrorKind::EmptyPath)
}
pub(crate) fn invalid_segment(segment: String) -> Self {
Error::new(ErrorKind::InvalidSegment(segment))
}
}
impl std::error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match &self.kind {
ErrorKind::EmptyPath => f.write_str("Empty path"),
ErrorKind::InvalidSegment(segment) => write!(
f,
"Invalid path segment: `{}` is not an identifier",
segment
),
}
}
}
#[derive(Debug)]
enum ErrorKind {
EmptyPath,
InvalidSegment(String),
}