macro_rules! doc_normalized {
() => {
"Domain names are normalized to lowercase."
};
}
macro_rules! doc_name_normalized {
() => {
"The name is normalized to lowercase."
};
}
macro_rules! doc_lowercase_required {
($owned:ident) => {
concat!(
"Domain names must already be in lowercase. Use [`",
stringify!($owned),
"`](crate::",
stringify!($owned),
") to parse mixed-case input."
)
};
}
macro_rules! doc_name_lowercase_required {
() => {
"The name must already be in lowercase. Use [`Domain`](crate::Domain) to parse mixed-case input."
};
}
macro_rules! doc_ignored_zone {
() => {
"A numeric IPv6 zone is accepted & ignored: `[fe80::1%1]:80` parses as `[fe80::1]:80`."
};
}
macro_rules! doc_recovers_value {
($value:literal) => {
concat!(
"The error contains the unmodified `",
$value,
"`, which `TryFrom<String>` soundly recovers as a string."
)
};
}
pub(crate) use doc_ignored_zone;
pub(crate) use doc_lowercase_required;
pub(crate) use doc_name_lowercase_required;
pub(crate) use doc_name_normalized;
pub(crate) use doc_normalized;
pub(crate) use doc_recovers_value;
macro_rules! impl_parse {
($ty:ident, $parse:ident $(, $doc:expr)*) => {
impl ::std::str::FromStr for crate::$ty {
type Err = crate::ParseError;
$(#[doc = $doc])*
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::$parse(s.as_bytes())
}
}
impl TryFrom<&str> for crate::$ty {
type Error = crate::ParseError;
$(#[doc = $doc])*
fn try_from(s: &str) -> Result<Self, Self::Error> {
Self::$parse(s.as_bytes())
}
}
};
($ty:ident $(, $doc:expr)*) => {
crate::impl_parse!($ty, try_from $(, $doc)*);
};
}
macro_rules! impl_parse_string {
($ty:ident $(, $doc:expr)*) => {
impl TryFrom<String> for crate::$ty {
type Error = crate::InvalidAddress<String>;
$(#[doc = $doc])*
fn try_from(value: String) -> Result<Self, Self::Error> {
let len: usize = value.len();
Self::try_from(value.into_bytes()).map_err(|error| unsafe { error.into_string_unchecked(len) })
}
}
};
}
macro_rules! impl_parse_ref {
($ty:ident $(, $doc:expr)*) => {
impl<'a> TryFrom<&'a str> for crate::$ty<'a> {
type Error = crate::ParseError;
$(#[doc = $doc])*
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Self::try_from(s.as_bytes())
}
}
};
}
pub(crate) use impl_parse;
pub(crate) use impl_parse_ref;
pub(crate) use impl_parse_string;