#[cfg(doc)]
use super::{AsciiDomain, DomainOrigin, Port, RpId, Scheme, Url};
#[cfg(doc)]
use core::str::FromStr;
use core::{
error::Error,
fmt::{self, Display, Formatter},
num::ParseIntError,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AsciiDomainErr {
Empty,
RootDomain,
Len,
EmptyLabel,
LabelLen,
NotAscii,
}
impl Display for AsciiDomainErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(match *self {
Self::Empty => "domain is empty",
Self::RootDomain => "domain is the root domain",
Self::Len => "domain is too long",
Self::EmptyLabel => "domain has an empty label",
Self::LabelLen => "domain has a label that is too long",
Self::NotAscii => "domain has a label that contains a non-ASCII byte",
})
}
}
impl Error for AsciiDomainErr {}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UrlErr;
impl Display for UrlErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("URL serializer failed")
}
}
impl Error for UrlErr {}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RpIdErr;
impl Display for RpIdErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("RpId is invalid")
}
}
impl Error for RpIdErr {}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SchemeParseErr;
impl Display for SchemeParseErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("scheme was empty")
}
}
impl Error for SchemeParseErr {}
#[derive(Debug, Eq, PartialEq)]
pub enum PortParseErr {
ParseInt(ParseIntError),
NotCanonical,
}
impl Display for PortParseErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self {
Self::ParseInt(ref err) => err.fmt(f),
Self::NotCanonical => {
f.write_str("string was a valid TCP/UDP port number, but it had leading 0s")
}
}
}
}
impl Error for PortParseErr {}
#[derive(Debug, Eq, PartialEq)]
pub enum DomainOriginParseErr {
Scheme(SchemeParseErr),
Port(PortParseErr),
}
impl Display for DomainOriginParseErr {
#[inline]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self {
Self::Scheme(err) => err.fmt(f),
Self::Port(ref err) => err.fmt(f),
}
}
}
impl Error for DomainOriginParseErr {}