Enum ip_network::IpNetwork[][src]

pub enum IpNetwork {
    V4(Ipv4Network),
    V6(Ipv6Network),
}
Expand description

Holds IPv4 or IPv6 network.

Variants

Tuple Fields of V4

0: Ipv4Network

Tuple Fields of V6

0: Ipv6Network

Implementations

Constructs new IpNetwork based on IpAddr and netmask.

Examples
use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
use ip_network::{IpNetwork, Ipv4Network};

let network_address = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 0));
let ip_network = IpNetwork::new(network_address, 24)?;
assert_eq!(ip_network.network_address(), IpAddr::V4(Ipv4Addr::new(192, 168, 1, 0)));
assert_eq!(ip_network.netmask(), 24);

Constructs new IpNetwork based on IpAddr and netmask with truncating host bits from given network_address.

Returns error if netmask is bigger than 32 for IPv4 and 128 for IPv6.

Examples
use std::net::{IpAddr, Ipv4Addr};
use ip_network::IpNetwork;

let network_address = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 128));
let ip_network = IpNetwork::new_truncate(network_address, 24)?;
assert_eq!(ip_network.network_address(), IpAddr::V4(Ipv4Addr::new(192, 168, 1, 0)));
assert_eq!(ip_network.netmask(), 24);

Returns network IP address.

Examples
use std::net::{IpAddr, Ipv4Addr};
use ip_network::IpNetwork;

let ip_network = IpNetwork::new(Ipv4Addr::new(192, 168, 1, 0), 24)?;
assert_eq!(ip_network.network_address(), IpAddr::V4(Ipv4Addr::new(192, 168, 1, 0)));

Returns network mask as integer.

Examples
use std::net::{IpAddr, Ipv4Addr};
use ip_network::IpNetwork;

let ip_network = IpNetwork::new(Ipv4Addr::new(192, 168, 1, 0), 24)?;
assert_eq!(ip_network.netmask(), 24);

Returns true if IpNetwork contains Ipv4Network struct.

Returns true if IpNetwork contains Ipv6Network struct.

Returns true if IpNetwork contains IpAddr. For different network type (for example IpNetwork is IPv6 and IpAddr is IPv4) always returns false.

Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use ip_network::IpNetwork;

let ip_network = IpNetwork::new(Ipv4Addr::new(192, 168, 1, 0), 24)?;
assert!(ip_network.contains(Ipv4Addr::new(192, 168, 1, 25)));
assert!(!ip_network.contains(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 1, 0, 0)));

Returns true if the network is default route, that contains all IP addresses.

Returns true if the network is part of multicast network range.

Returns true if this is a part of network reserved for documentation.

Returns true if this network is inside loopback address range.

Returns true if the network appears to be globally routable.

Converts string in format IPv4 (X.X.X.X/Y) or IPv6 (X:X::X/Y) CIDR notation to IpNetwork.

Examples
use std::net::Ipv4Addr;
use ip_network::{IpNetwork, Ipv4Network};

let ip_network = IpNetwork::from_str_truncate("192.168.1.1/24").unwrap();
assert_eq!(ip_network, IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(192, 168, 1, 0), 24).unwrap()));

Return an iterator of the collapsed IpNetworks.

Trait Implementations

The expression being returned

Perform the conversion

The expression being returned

Perform the conversion

The expression being returned

Perform the conversion

The expression being returned

Perform the conversion

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

Converts IpNetwork to string in format X.X.X.X/Y for IPv4 and X:X::X/Y for IPv6 (CIDR notation).

Examples
use std::net::Ipv4Addr;
use ip_network::{IpNetwork, Ipv4Network};

let ip_network = IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(192, 168, 1, 0), 24)?);
assert_eq!(ip_network.to_string(), "192.168.1.0/24");

Converts IpAddr to IpNetwork with netmask 32 for IPv4 address and 128 for IPv6 address.

Converts Ipv4Addr to IpNetwork with netmask 32.

Performs the conversion.

Converts Ipv6Addr to IpNetwork with netmask 128.

Performs the conversion.

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more

Determines if a value of this type can be created from the specified Postgres Type. Read more

Creates a new value of this type from a NULL SQL value. Read more

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw. Read more

See the trait documentation.

See the trait documentation.

The number of fields that this type will consume. Must be equal to the number of times you would call row.take() in build_from_row Read more

Converts string in format IPv4 (X.X.X.X/Y) or IPv6 (X:X::X/Y) CIDR notation to IpNetwork.

Examples
use std::net::Ipv4Addr;
use std::str::FromStr;
use ip_network::{IpNetwork, Ipv4Network};

let ip_network = IpNetwork::from_str("192.168.1.0/24").unwrap();
assert_eq!(ip_network, IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(192, 168, 1, 0), 24).unwrap()));

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

This method tests for !=.

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

This method tests for !=.

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

This method tests for !=.

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The Rust type you’d like to map from. Read more

Construct an instance of this type

Serialize this value into the given Serde serializer. Read more

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more

Determines if a value of this type can be converted to the specified Postgres Type. Read more

An adaptor method used internally by Rust-Postgres. Read more

See the trait documentation.

See the trait documentation.

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 a reference to self as a ToSql trait object.

Performs the conversion.

Performs the conversion.

Convert self to an expression for Diesel’s query builder. Read more

Convert &self to an expression for Diesel’s query builder. Read more

Should always be Self

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)

recently added

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.