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
Unresolved Questions
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
consttraits are still a long ways out, this provides aconstversion of the conversions to/from integers that people can use in the meantime.Public API
Steps / History
IpvNAddr::{BITS, to_bits, from_bits}(ip_bits) #125551Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html ↩
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩