Struct iprange::Subnet
[−]
[src]
pub struct Subnet { pub prefix: CompactIpv4, pub prefix_size: usize, }
Represents a subdivision of an IP network.
We use CIDR notation to repesent a subnetwork.
Thus, a Subnet
is composed with a prefix
and the size of the subnet
written after a slash (/
). The size of the subnet is
represented by prefix_size
, which is the count of leading ones
in the subnet mask.
Subnet
implements FromStr
so that users can easily convert a
string slice to a Subnet
. Currently, two formats are supported:
a.b.c.d/prefix_size
(e.g.10.0.0.0/8
)a.b.c.d/mask
(e.g.192.168.0.0/255.255.255.0
)
The subnet will be automatically fixed after parsing. For example:
parsing 172.16.32.1/16
results in 172.16.0.0/16
.
Fields
prefix: CompactIpv4
The prefix IP of the subnet
prefix_size: usize
The count of leading ones of the subnet mask
Methods
impl Subnet
[src]
fn contains<T: Into<CompactIpv4>>(&self, addr: T) -> bool
[src]
Tests if self
contains the IP addr
.
fn end(&self) -> CompactIpv4
[src]
Returns the last IP in self
.
fn includes(&self, other: Subnet) -> bool
[src]
Tests if self
includes other
, in other words,
self
is a supernetwork of other
.
fn mask(&self) -> CompactIpv4
[src]
Returns the subnet mask of self
.
Trait Implementations
impl PartialEq for Subnet
[src]
fn eq(&self, __arg_0: &Subnet) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Subnet) -> bool
[src]
This method tests for !=
.
impl Eq for Subnet
[src]
impl Clone for Subnet
[src]
fn clone(&self) -> Subnet
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Subnet
[src]
impl From<CompactIpv4> for Subnet
[src]
fn from(ip: CompactIpv4) -> Subnet
[src]
Performs the conversion.