Crate cidr [] [src]

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

Feature serde

This feature is enabled by default (not using serde-derive, only serde).

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

Reexports

pub use Family::*;

Structs

InetIterator

Iterator type to iterate over a list of IP addresses in a network

Ipv4Cidr

Cidr type representing an IPv4 network

Ipv4Inet

Inet type representing an IPv4 host within a network

Ipv6Cidr

Cidr type representing an IPv6 network

Ipv6Inet

Inet type representing an IPv6 host within a network

NetworkLengthTooLongError

Error returned when the network length was longer than the address

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

NetworkParseError

Error type returned when parsing IP networks

Traits

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.