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 for the underlying address (IpAddr, Ipv4Addr or Ipv6Addr).

Corresponding Inet type (representing an address + a network containing it)

Required Methods

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.

Create a network containing a single address (network length = address length).

first address in the network as plain address

first address in the network

last address in the network as plain address

last address in the network

length in bits of the shared prefix of the contained addresses

IP family of the contained address (Ipv4 or Ipv6).

network mask: an pseudo address which has the first network length bits set to 1 and the remaining to 0.

check whether an address is contained in the network

Provided Methods

Iterate over all addresses in the range. With IPv6 addresses this can produce really long iterations (up to 2128 addresses).

Implementors