diff --git a/url/src/host.rs b/url/src/host.rs index bfe1e2c9..e4f69cdd 100644 --- a/url/src/host.rs +++ b/url/src/host.rs @@ -6,7 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use crate::net::{Ipv4Addr, Ipv6Addr}; +use crate::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use alloc::borrow::Cow; use alloc::borrow::ToOwned; use alloc::string::String; @@ -200,6 +200,27 @@ where } } +impl From for Host { + fn from(ipv4: Ipv4Addr) -> Self { + Self::Ipv4(ipv4) + } +} + +impl From for Host { + fn from(ipv6: Ipv6Addr) -> Self { + Self::Ipv6(ipv6) + } +} + +impl From for Host { + fn from(ip: IpAddr) -> Self { + match ip { + IpAddr::V4(ipv4) => ipv4.into(), + IpAddr::V6(ipv6) => ipv6.into(), + } + } +} + fn write_ipv6(addr: &Ipv6Addr, f: &mut Formatter<'_>) -> fmt::Result { let segments = addr.segments(); let (compress_start, compress_end) = longest_zero_sequence(&segments);