Trait cidr::Cidr
[−]
[src]
pub trait Cidr: Sized { type Address; type Inet: Inet<Address = Self::Address>; fn new(addr: Self::Address, len: u8) -> Result<Self, NetworkParseError>; fn new_host(addr: Self::Address) -> Self; fn first_address(&self) -> Self::Address; fn first(&self) -> Self::Inet; fn last_address(&self) -> Self::Address; fn last(&self) -> Self::Inet; fn network_length(&self) -> u8; fn family(&self) -> Family; fn mask(&self) -> Self::Address; fn contains(&self, addr: &Self::Address) -> bool; fn iter(&self) -> InetIterator<Self::Inet> { ... } }
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.
Associated Types
type Address
Type for the underlying address (IpAddr
, Ipv4Addr
or
Ipv6Addr
).
type Inet: Inet<Address = Self::Address>
Corresponding Inet
type (representing an address + a network
containing it)
Required Methods
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.
fn new_host(addr: Self::Address) -> Self
Create a network containing a single address (network length = address length).
fn first_address(&self) -> Self::Address
first address in the network as plain address
fn first(&self) -> Self::Inet
first address in the network
fn last_address(&self) -> Self::Address
last address in the network as plain address
fn last(&self) -> Self::Inet
last address in the network
fn network_length(&self) -> u8
length in bits of the shared prefix of the contained addresses
fn family(&self) -> Family
IP family of the contained address (Ipv4
or Ipv6
).
fn mask(&self) -> Self::Address
network mask: an pseudo address which has the first network length
bits set to 1 and the remaining to 0.
fn contains(&self, addr: &Self::Address) -> bool
check whether an address is contained in the network
Provided Methods
fn iter(&self) -> InetIterator<Self::Inet>
Iterate over all addresses in the range. With IPv6 addresses this can produce really long iterations (up to 2128 addresses).