macro_rules! impl_parse {
($ty:ident $(, $doc:expr)*) => {
impl ::std::str::FromStr for crate::$ty {
type Err = crate::ParseError;
$(#[doc = $doc])*
fn from_str(text: &str) -> Result<Self, Self::Err> {
Self::parse(text.as_bytes())
}
}
impl TryFrom<&str> for crate::$ty {
type Error = crate::ParseError;
$(#[doc = $doc])*
fn try_from(text: &str) -> Result<Self, Self::Error> {
Self::parse(text.as_bytes())
}
}
};
}
macro_rules! impl_parse_string {
($ty:ident $(, $doc:expr)*) => {
impl TryFrom<String> for crate::$ty {
type Error = crate::InvalidAddressError<String>;
$(#[doc = $doc])*
fn try_from(value: String) -> Result<Self, Self::Error> {
let len: usize = value.len();
Self::parse_vec(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(text: &'a str) -> Result<Self, Self::Error> {
Self::parse(text.as_bytes())
}
}
};
}
pub(crate) use impl_parse;
pub(crate) use impl_parse_ref;
pub(crate) use impl_parse_string;