1use std::fmt;
2
3#[derive(Debug)]
5pub struct Error {
6 kind: ErrorKind,
7}
8
9impl Error {
10 fn new(kind: ErrorKind) -> Self {
11 Error { kind }
12 }
13
14 pub(crate) fn empty_path() -> Self {
16 Error::new(ErrorKind::EmptyPath)
17 }
18
19 pub(crate) fn invalid_segment(segment: String) -> Self {
22 Error::new(ErrorKind::InvalidSegment(segment))
23 }
24}
25
26impl std::error::Error for Error {}
27
28impl fmt::Display for Error {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 match &self.kind {
31 ErrorKind::EmptyPath => f.write_str("Empty path"),
32 ErrorKind::InvalidSegment(segment) => write!(
33 f,
34 "Invalid path segment: `{}` is not an identifier",
35 segment
36 ),
37 }
38 }
39}
40
41#[derive(Debug)]
42enum ErrorKind {
43 EmptyPath,
45 InvalidSegment(String),
48}