Closed
Description
Feature gate: #![feature(ip_bits)]
This is a tracking issue for IpvNAddr::{BITS, to_bits, from_bits}
.
This API exists mostly so that users can be explicit about various bit operations which are useful for computing IP networks (see ACP linked below). For example, IpvNAddr::BITS - ip.to_bits().trailing_zeros()
can be used to determine the network prefix length of a given address.
Additionally, since const
traits are still a long ways out, this provides a const
version of the conversions to/from integers that people can use in the meantime.
Public API
impl Ipv4Addr {
pub const BITS: u32 = 32;
pub const fn from_bits(bits: u32) -> Ipv4Addr;
pub const fn to_bits(self) -> u32;
}
impl Ipv6Addr {
pub const BITS: u32 = 128;
pub const fn from_bits(bits: u128) -> Ipv4Addr;
pub const fn to_bits(self) -> u128;
}
Steps / History
- API change proposal (ACP)1: ACP: Extended logic for IP networks libs-team#235
- Implementation: Add BITS, from_bits, to_bits to IP addresses #113746
- Improve docs regarding endianness: Elaborate on ip_addr bit conversion endianness #118505
- Final comment period (FCP)2
- Stabilization PR: Stabilise
IpvNAddr::{BITS, to_bits, from_bits}
(ip_bits
) #125551
Unresolved Questions
- None yet.