Crate cidr

Source
Expand description

This library provides types to represent an IP network (Cidr) or an IP host withing a network (Inet)

The naming follows the names of the PostgreSQL data types

By default address parsing is done using FromStr from the standard library, which is rather strict in the inputs it accepts. Cidr types don’t accept addresses with host-bits set (i.e. 127.0.0.1/8 isn’t valid; it should be 127.0.0.0/8).

Custom parsing can be implemented using the helpers in the parsers module.

If the # flag is used with the Display formatting (i.e. {:#}) the prefix length will be shown even for host addresses (added in 0.1.1).

§Feature no_unsafe

Enables #![forbid(unsafe_code)] for the whole crate; needs to use some workarounds that are likely slower than their unsafe variants.

§Feature std

Enabled by default, currently unused.

§Feature serde

This feature enables various types to be serialized using serde (without serde-derive).

In human readable formats the Display and FromStr interfaces are used. Otherwise all values are serialized in the same format (apart from the newtype wrapping) as a tuple of two values:

  • tag: u8:
    • 0x00...0x20: IPv4 with network length tag
    • 0x40...0xc0: IPv6 with network length tag - 0x40
    • 0xff: any
  • address according to tag: Ipv4Addr ([u8; 4]), Ipv6Addr ([u8; 16]) or ()

The represenation hasn’t been changed in 0.2; it is compatible with 0.1.

§Feature bitstring

This feature allows various types to be used as bitstring::BitString, which allows them being in used in containers like bitstring-trees.

Modules§

errors
Various error types returned by function in this crate
parsers
Extra parsers

Structs§

InetAddressIterator
Iterator type to iterate over a list of IP addresses in a network
InetIterator
Iterator type to iterate over a list of IP addresses within a network
Ipv4Cidr
Cidr type representing an IPv4 network
Ipv4Inet
Inet type representing an IPv4 host within a network
Ipv4InetPair
InetPair type representing a pair of IPv4 hosts within a network
Ipv6Cidr
Cidr type representing an IPv6 network
Ipv6Inet
Inet type representing an IPv6 host within a network
Ipv6InetPair
InetPair type representing a pair of IPv6 hosts within a network

Enums§

AnyIpCidr
Represents either an IPv4 or an IPv6 network or “any”.
Family
Represents the type of an IP address
IpCidr
Cidr type representing either an IPv4 or an IPv6 network
IpInet
Inet type representing either an IPv4 or an IPv6 host within a network
IpInetPair
InetPair type representing either a pair of IPv4 host or a pair of IPv6 hosts within a network

Traits§

Address
Maps IP address type to other types based on this address type
Cidr
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.
Inet
Types implementing Inet represent IP hosts within networks.
InetPair
Pair of two addresses in the same network