Trait cidr::Cidr

source ·
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§

source

type Address: Address<Cidr = Self>

Type for the underlying address (IpAddr, Ipv4Addr or Ipv6Addr).

Required Methods§

source

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.

source

fn new_host(addr: Self::Address) -> Self

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

source

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).

source

fn first_address(&self) -> Self::Address

first address in the network as plain address

source

fn first(&self) -> <Self::Address as Address>::Inet

first address in the network

source

fn last_address(&self) -> Self::Address

last address in the network as plain address

source

fn last(&self) -> <Self::Address as Address>::Inet

last address in the network

source

fn network_length(&self) -> u8

length in bits of the shared prefix of the contained addresses

source

fn family(&self) -> Family

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

source

fn is_host_address(&self) -> bool

whether network represents a single host address

source

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.

source

fn contains(&self, addr: &Self::Address) -> bool

check whether an address is contained in the network

Implementors§