publicsuffix/
error.rs

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