Enum ip_network::IpNetwork[][src]

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

Holds IPv4 or IPv6 network

Variants

Methods

impl IpNetwork
[src]

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::from_str("192.168.1.0").unwrap();
let ip_network = IpNetwork::from(network_address, 24).unwrap();
assert_eq!(ip_network, IpNetwork::V4(Ipv4Network::from(Ipv4Addr::new(192, 168, 1, 0), 24).unwrap()));

Returns true if IpNetwork contains Ipv4Network struct

Returns true if IpNetwork contains Ipv6Network struct

Trait Implementations

impl Clone for IpNetwork
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Eq for IpNetwork
[src]

impl PartialEq for IpNetwork
[src]

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

This method tests for !=.

impl Debug for IpNetwork
[src]

Formats the value using the given formatter. Read more

impl Hash for IpNetwork
[src]

Feeds this value into the given [Hasher]. Read more

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

impl PartialOrd for IpNetwork
[src]

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

impl Ord for IpNetwork
[src]

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

impl FromStr for IpNetwork
[src]

The associated error which can be returned from parsing.

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::from(Ipv4Addr::new(192, 168, 1, 0), 24).unwrap()));

impl Display for IpNetwork
[src]

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::from(Ipv4Addr::new(192, 168, 1, 0), 24).unwrap());
assert_eq!(format!("{}", ip_network), "192.168.1.0/24");

impl From<Ipv4Network> for IpNetwork
[src]

Performs the conversion.

impl From<Ipv6Network> for IpNetwork
[src]

Performs the conversion.

Auto Trait Implementations

impl Send for IpNetwork

impl Sync for IpNetwork