Skip to content
Open
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
23 changes: 22 additions & 1 deletion url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,6 +200,27 @@ where
}
}

impl From<Ipv4Addr> for Host {
fn from(ipv4: Ipv4Addr) -> Self {
Self::Ipv4(ipv4)
}
}

impl From<Ipv6Addr> for Host {
fn from(ipv6: Ipv6Addr) -> Self {
Self::Ipv6(ipv6)
}
}

impl From<IpAddr> 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);
Expand Down