pub struct PrefixKey { /* private fields */ }Expand description
“This address at this prefix length” as a fixed-size Copy hash key.
§Examples
use net_io::{PrefixKey, PrefixPolicy};
let a = PrefixKey::of("2001:db8:1:2::10".parse().unwrap(), PrefixPolicy::DEFAULT);
let b = PrefixKey::of("2001:db8:1:2:ffff::1".parse().unwrap(), PrefixPolicy::DEFAULT);
assert_eq!(a, b);
let wide = PrefixPolicy::new(24, 48)?;
assert_eq!(PrefixKey::of("192.0.2.200".parse().unwrap(), wide).to_string(), "192.0.2.0/24");Implementations§
Source§impl PrefixKey
impl PrefixKey
Sourcepub fn of(ip: IpAddr, policy: PrefixPolicy) -> PrefixKey
pub fn of(ip: IpAddr, policy: PrefixPolicy) -> PrefixKey
The key of ip under policy (normalized first; scope ids ignored).
Sourcepub fn exact(ip: IpAddr) -> PrefixKey
pub fn exact(ip: IpAddr) -> PrefixKey
The key of the single address (/32 or /128).
let key = net_io::PrefixKey::exact("10.0.0.1".parse().unwrap());
assert_eq!(key.prefix_len(), 32);Sourcepub fn network(&self) -> IpAddr
pub fn network(&self) -> IpAddr
The network address of the key.
let key = net_io::PrefixKey::of("10.1.2.3".parse().unwrap(), net_io::PrefixPolicy::new(8, 64)?);
assert_eq!(key.network().to_string(), "10.0.0.0");Sourcepub fn prefix_len(&self) -> u8
pub fn prefix_len(&self) -> u8
The prefix length of the key.
Trait Implementations§
impl Copy for PrefixKey
impl Eq for PrefixKey
Source§impl Ord for PrefixKey
impl Ord for PrefixKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for PrefixKey
impl PartialOrd for PrefixKey
impl StructuralPartialEq for PrefixKey
Auto Trait Implementations§
impl Freeze for PrefixKey
impl RefUnwindSafe for PrefixKey
impl Send for PrefixKey
impl Sync for PrefixKey
impl Unpin for PrefixKey
impl UnsafeUnpin for PrefixKey
impl UnwindSafe for PrefixKey
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