pub struct IpPrefix { /* private fields */ }Expand description
An IP address with a CIDR prefix length.
Equivalent to Go’s netip.Prefix — an IpAddr plus a prefix length in
bits (0–32 for v4, 0–128 for v6).
let p = IpPrefix::new(Ipv4Addr::new(10, 0, 0, 1).into(), 24);
assert!(p.contains(Ipv4Addr::new(10, 0, 0, 99).into()));
assert!(!p.contains(Ipv4Addr::new(10, 0, 1, 1).into()));Implementations§
Source§impl IpPrefix
impl IpPrefix
Sourcepub fn new(addr: IpAddr, bits: u8) -> IpPrefix
pub fn new(addr: IpAddr, bits: u8) -> IpPrefix
Construct a prefix. bits is clamped silently to the protocol max:
at most 32 for v4 and 128 for v6.
Sourcepub fn addr(self) -> IpAddr
pub fn addr(self) -> IpAddr
The address part. May or may not have the host bits zeroed; this matches
Go’s semantics so that 10.0.0.5/24 round-trips with the host bits.
Sourcepub fn contains(self, other: IpAddr) -> bool
pub fn contains(self, other: IpAddr) -> bool
True if other falls within this prefix (host bits ignored).
Trait Implementations§
impl Copy for IpPrefix
impl Eq for IpPrefix
impl StructuralPartialEq for IpPrefix
Auto Trait Implementations§
impl Freeze for IpPrefix
impl RefUnwindSafe for IpPrefix
impl Send for IpPrefix
impl Sync for IpPrefix
impl Unpin for IpPrefix
impl UnsafeUnpin for IpPrefix
impl UnwindSafe for IpPrefix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more