Skip to main content

tld/
error.rs

1use core::fmt;
2
3/// Errors returned by this crate
4#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
5#[non_exhaustive]
6pub enum Error {
7    EmptyLabel(String),
8    ExceptionAtFirstLabel(String),
9    InvalidList,
10    InvalidRule(String),
11    ListNotUtf8Encoded,
12}
13
14impl fmt::Display for Error {
15    #[inline]
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match self {
18            Error::EmptyLabel(rule) => write!(f, "rule `{}` contains an empty label", rule),
19            Error::ExceptionAtFirstLabel(rule) => {
20                write!(f, "`{}`; exceptions only valid at end of rule", rule)
21            }
22            Error::InvalidList => write!(f, "the provided list is not valid"),
23            Error::InvalidRule(rule) => write!(f, "rule `{}` is invalid", rule),
24            Error::ListNotUtf8Encoded => write!(f, "the provided list is not UTF8 encoded"),
25        }
26    }
27}
28
29impl std::error::Error for Error {}