Struct bdrck::net::IpNet

source ·
pub struct IpNet { /* private fields */ }
Expand description

An IpNet represents an IP network. Networks are typically identified in CIDR notation, like (for example) “192.0.0.0/24”.

Implementations

Return the network IP. This address will have been normalized, such that any non-masked bits will have been turned off during construction.

Return the network mask, as a byte slice. This slice will always be 16 bytes long, even if this is an IPv4 network.

Apply this network’s mask to the given IP address, returning the modified copy.

The “default” behavior is when invert=false and set=false. In this case, any bits which are “0” in the mask are turned off in the given IP address’ bytes.

If invert=true, then each bit in the mask is flipped before it is applied - in other words, we apply the inverse mask.

If set=true, then we switch from bitwise AND to bitwise OR, meaning instead of the behavior described above, any bits which are “1” in the mask are turned on in the IP address, and other bits are left unchanged.

Returns the number of “1” bits in this network’s mask. Although the mask is always 16 bytes long, for IPv4 networks only the last 4 bytes of the mask are considered.

Returns whether or not this network’s mask is “canonical” - i.e., if all of its mask’s “1” bits are contiguous (no “0” bits in-between them).

Return the netmask IP address for this network.

Return the broadcast IP address for this network.

Return whether or not the given IP address is contained within this network. If strict=true, then the “network address” and “broadcast address” are both not considered to be “within” this network (this is useful if you want to check if the given IP address is actually usable for a host on the network).

Increment the given IP address as if with increment_ip(), but returning None if the resulting IP address does not lie within this network. The “strict” parameter behaves as IpNet::contains() describes.

Return the first IP address which falls within this network.

Return the last non-broadcast IP address which falls within this network.

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
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. 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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

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
Compare self to key and return true if they are equal.

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
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. 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.