pub struct Netv4Addr { /* private fields */ }Expand description
A structure representing an IPv4 network.
Internally, this structure includes two values; an Ipv4Addr
representing the network address (addr), and another
representing the netmask (mask).
Implementations§
Source§impl Netv4Addr
impl Netv4Addr
pub const fn mask(&self) -> Ipv4Addr
pub const fn addr(&self) -> Ipv4Addr
pub fn is_cidr(&self) -> bool
Sourcepub fn new(addr: Ipv4Addr, mask: Ipv4Addr) -> Self
pub fn new(addr: Ipv4Addr, mask: Ipv4Addr) -> Self
Create a new Netv4Addr from the given addr and mask.
Masks the given addr value with the given mask before
the structure containing both is returned.
§Examples
let network = Ipv4Addr::new(127, 0, 1, 1);
let netmask = Ipv4Addr::new(255, 0, 0, 0);
let netaddr = Netv4Addr::new(network, netmask);
// We do need to have the `Contains` trait in scope to use it...
use netaddr2::Contains;
let test: Ipv4Addr = Ipv4Addr::new(127, 47, 23, 37);
assert!(netaddr.contains(&test));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Netv4Addr
impl<'de> Deserialize<'de> for Netv4Addr
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromStr for Netv4Addr
impl FromStr for Netv4Addr
Source§fn from_str(string: &str) -> Result<Self>
fn from_str(string: &str) -> Result<Self>
Parse a Netv4Addr from a string
Often used implicitly, this implementation allows for a few formats to be given:
- (Standard) CIDR format:
192.0.2.16/29 - Extended format (
-delimited):192.0.2.16 255.255.255.248 - Extended format (
/-delimited):192.0.2.16/255.255.255.248
§Examples
let parsed: Netv4Addr = "192.0.2.16/29".parse().unwrap();
let addr: std::net::Ipv4Addr = "192.0.2.16".parse().unwrap();
let mask: std::net::Ipv4Addr = "255.255.255.248".parse().unwrap();
assert_eq!(parsed, Netv4Addr::new(addr, mask));let parsed: Netv4Addr = "192.0.2.16 255.255.255.248".parse().unwrap();
let addr: std::net::Ipv4Addr = "192.0.2.16".parse().unwrap();
let mask: std::net::Ipv4Addr = "255.255.255.248".parse().unwrap();
assert_eq!(parsed, Netv4Addr::new(addr, mask));let parsed: Netv4Addr = "192.0.2.16/255.255.255.248".parse().unwrap();
let addr: std::net::Ipv4Addr = "192.0.2.16".parse().unwrap();
let mask: std::net::Ipv4Addr = "255.255.255.248".parse().unwrap();
assert_eq!(parsed, Netv4Addr::new(addr, mask));Source§impl Ord for Netv4Addr
impl Ord for Netv4Addr
Source§impl PartialOrd for Netv4Addr
impl PartialOrd for Netv4Addr
impl Copy for Netv4Addr
impl Eq for Netv4Addr
impl StructuralPartialEq for Netv4Addr
Auto Trait Implementations§
impl Freeze for Netv4Addr
impl RefUnwindSafe for Netv4Addr
impl Send for Netv4Addr
impl Sync for Netv4Addr
impl Unpin for Netv4Addr
impl UnwindSafe for Netv4Addr
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