pub enum CidrSubnet {
    V4([u8; 4][u8; 4]),
    V6([u8; 16][u8; 16]),
}
Expand description

CIDR subnet, as per RFC 4632

You might know CIDR subnets better by their textual representation where they consist of an ip address followed by a slash and a prefix number, for example 192.168.99.0/24.

The first field in the enum is the address, the second is the mask. Both are specified in network byte order.

Variants

V4([u8; 4][u8; 4])

V6([u8; 16][u8; 16])

Implementations

Obtains the CidrSubnet from the well-known addr/prefix notation.

// The "192.0.2.0/24" example from
// https://tools.ietf.org/html/rfc5280#page-42
let subnet = CidrSubnet::from_str("192.0.2.0/24").unwrap();
assert_eq!(subnet, CidrSubnet::V4([0xC0, 0x00, 0x02, 0x00], [0xFF, 0xFF, 0xFF, 0x00]));

Obtains the CidrSubnet from an ip address as well as the specified prefix number.

// The "192.0.2.0/24" example from
// https://tools.ietf.org/html/rfc5280#page-42
let addr = IpAddr::from_str("192.0.2.0").unwrap();
let subnet = CidrSubnet::from_addr_prefix(addr, 24);
assert_eq!(subnet, CidrSubnet::V4([0xC0, 0x00, 0x02, 0x00], [0xFF, 0xFF, 0xFF, 0x00]));

Obtains the CidrSubnet from an IPv4 address in network byte order as well as the specified prefix.

Obtains the CidrSubnet from an IPv6 address in network byte order as well as the specified prefix.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.