Skip to content

Commit

Permalink
feat: more from impls for ServerName and IpAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh authored and djc committed Sep 22, 2024
1 parent 775ef66 commit bd6a082
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/server_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,45 @@ impl<'a> TryFrom<&'a str> for ServerName<'a> {
}
}

impl From<IpAddr> for ServerName<'_> {
fn from(addr: IpAddr) -> Self {
Self::IpAddress(addr)
}
}

#[cfg(feature = "std")]
impl From<std::net::IpAddr> for ServerName<'_> {
fn from(addr: std::net::IpAddr) -> Self {
Self::IpAddress(addr.into())
}
}

impl From<Ipv4Addr> for ServerName<'_> {
fn from(v4: Ipv4Addr) -> Self {
Self::IpAddress(IpAddr::V4(v4))
}
}

impl From<Ipv6Addr> for ServerName<'_> {
fn from(v6: Ipv6Addr) -> Self {
Self::IpAddress(IpAddr::V6(v6))
}
}

#[cfg(feature = "std")]
impl From<std::net::Ipv4Addr> for ServerName<'_> {
fn from(v4: std::net::Ipv4Addr) -> Self {
Self::IpAddress(IpAddr::V4(v4.into()))
}
}

#[cfg(feature = "std")]
impl From<std::net::Ipv6Addr> for ServerName<'_> {
fn from(v6: std::net::Ipv6Addr) -> Self {
Self::IpAddress(IpAddr::V6(v6.into()))
}
}

/// A type which encapsulates a string (borrowed or owned) that is a syntactically valid DNS name.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct DnsName<'a>(DnsNameInner<'a>);
Expand Down Expand Up @@ -369,6 +408,20 @@ impl From<IpAddr> for std::net::IpAddr {
}
}

#[cfg(feature = "std")]
impl From<std::net::Ipv4Addr> for IpAddr {
fn from(v4: std::net::Ipv4Addr) -> Self {
Self::V4(v4.into())
}
}

#[cfg(feature = "std")]
impl From<std::net::Ipv6Addr> for IpAddr {
fn from(v6: std::net::Ipv6Addr) -> Self {
Self::V6(v6.into())
}
}

/// `no_std` implementation of `std::net::Ipv4Addr`.
///
/// Note: because we intend to replace this type with `core::net::Ipv4Addr` as soon as it is
Expand Down

0 comments on commit bd6a082

Please sign in to comment.