Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more from impls for ServerName and IpAddr #55

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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