pub trait Cidr:
Copy
+ Debug
+ Ord
+ Hash
+ PrivCidr {
type Address: Address<Cidr = Self>;
// Required methods
fn new(addr: Self::Address, len: u8) -> Result<Self, NetworkParseError>;
fn new_host(addr: Self::Address) -> Self;
fn iter(&self) -> InetIterator<Self::Address> ⓘ;
fn first_address(&self) -> Self::Address;
fn first(&self) -> <Self::Address as Address>::Inet;
fn last_address(&self) -> Self::Address;
fn last(&self) -> <Self::Address as Address>::Inet;
fn network_length(&self) -> u8;
fn family(&self) -> Family;
fn is_host_address(&self) -> bool;
fn mask(&self) -> Self::Address;
fn contains(&self, addr: &Self::Address) -> bool;
}
Expand description
Types implementing Cidr
represent IP networks. An IP network in
this case is a set of IP addresses which share a common prefix (when
viewed as a bitstring). The length of this prefix is called
network_length
.
In the standard representation the network is identified by the first address and the network length, separated by a ‘/’.
The parsers will expect the input in the same format, i.e. only the first address of the network is accepted.
The first network length bits in an address representing the network are the network part, the remaining bits are the host part. Requiring an address to be the first in a network is equivalent to requiring the host part being zero.
Required Associated Types§
Required Methods§
sourcefn new(addr: Self::Address, len: u8) -> Result<Self, NetworkParseError>
fn new(addr: Self::Address, len: u8) -> Result<Self, NetworkParseError>
Create new network from address and prefix length. If the network length exceeds the address length or the address is not the first address in the network (“host part not zero”) an error is returned.
sourcefn new_host(addr: Self::Address) -> Self
fn new_host(addr: Self::Address) -> Self
Create a network containing a single address (network length = address length).
sourcefn iter(&self) -> InetIterator<Self::Address> ⓘ
fn iter(&self) -> InetIterator<Self::Address> ⓘ
Iterate over all addresses in the range. With IPv6 addresses this can produce really long iterations (up to 2128 addresses).
sourcefn first_address(&self) -> Self::Address
fn first_address(&self) -> Self::Address
first address in the network as plain address
sourcefn last_address(&self) -> Self::Address
fn last_address(&self) -> Self::Address
last address in the network as plain address
sourcefn network_length(&self) -> u8
fn network_length(&self) -> u8
length in bits of the shared prefix of the contained addresses
sourcefn is_host_address(&self) -> bool
fn is_host_address(&self) -> bool
whether network represents a single host address