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

Introduce unstable Ipv{4,6}AddrPrefix #86992

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
24 changes: 20 additions & 4 deletions library/std/src/net/ip.rs → library/std/src/net/ip/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Tests for this module
#[cfg(all(test, not(target_os = "emscripten")))]
mod tests;

use crate::cmp::Ordering;
use crate::fmt::{self, Write as FmtWrite};
use crate::hash;
Expand All @@ -10,6 +6,13 @@ use crate::mem::transmute;
use crate::sys::net::netc as c;
use crate::sys_common::{AsInner, FromInner, IntoInner};

// Tests for this module
#[cfg(all(test, not(target_os = "emscripten")))]
mod tests;

mod network;
pub use self::network::{Ipv4AddrPrefix, Ipv6AddrPrefix};

/// An IP address, either IPv4 or IPv6.
///
/// This enum can contain either an [`Ipv4Addr`] or an [`Ipv6Addr`], see their
Expand Down Expand Up @@ -314,6 +317,12 @@ impl Ipv4Addr {
Ipv4Addr { inner: c::in_addr { s_addr: u32::from_ne_bytes([a, b, c, d]) } }
}

// Private constructor to simplify const code.
// FIXME: remove when From<u32> becomes usable in const contexts.
const fn from_u32(address: u32) -> Ipv4Addr {
Ipv4Addr { inner: c::in_addr { s_addr: address.to_be() } }
}

/// An IPv4 address with the address pointing to localhost: `127.0.0.1`
///
/// # Examples
Expand Down Expand Up @@ -1113,6 +1122,13 @@ impl Ipv6Addr {
}
}

// Private constructor to simplify const code.
// FIXME: remove when From<u128> becomes usable in const contexts.
#[rustc_allow_const_fn_unstable(const_fn_transmute)]
const fn from_u128(address: u128) -> Ipv6Addr {
Ipv6Addr { inner: c::in6_addr { s6_addr: address.to_be_bytes() } }
}

/// An IPv6 address representing localhost: `::1`.
///
/// # Examples
Expand Down
Loading