Struct netaddr2::Netv4Addr [−][src]
pub struct Netv4Addr { /* fields omitted */ }
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
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
Deserialize this value from the given Serde deserializer. Read more
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 (
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));
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Netv4Addr
impl UnwindSafe for Netv4Addr
Blanket Implementations
Mutably borrows from an owned value. Read more