Tracking Issue for IpvNAddr::{BITS, to_bits, from_bits} (ip_bits) · Issue #113744 · rust-lang/rust (original) (raw)

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

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/api-change-proposals.html
  2. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html