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

Address parsing also accepts IPv4 address with less than four octets (but always parses those as decimal).

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

Feature std

Enabled by default, also mandatory right now because std::net isn’t available in core.

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

  • Various error types returned by function in this crate

Structs

Enums

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

Traits

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