Enum ip_network::IpNetwork [−][src]
pub enum IpNetwork { V4(Ipv4Network), V6(Ipv6Network), }
Holds IPv4 or IPv6 network
Variants
V4(Ipv4Network)
V6(Ipv6Network)
Methods
impl IpNetwork
[src]
impl IpNetwork
pub fn from<I: Into<IpAddr>>(
network_address: I,
netmask: u8
) -> Result<Self, IpNetworkError>
[src]
pub fn from<I: Into<IpAddr>>(
network_address: I,
netmask: u8
) -> Result<Self, IpNetworkError>
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()));
pub fn is_ipv4(&self) -> bool
[src]
pub fn is_ipv4(&self) -> bool
Returns true
if IpNetwork
contains Ipv4Network
struct
pub fn is_ipv6(&self) -> bool
[src]
pub fn is_ipv6(&self) -> bool
Returns true
if IpNetwork
contains Ipv6Network
struct
Trait Implementations
impl Clone for IpNetwork
[src]
impl Clone for IpNetwork
fn clone(&self) -> IpNetwork
[src]
fn clone(&self) -> IpNetwork
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Eq for IpNetwork
[src]
impl Eq for IpNetwork
impl PartialEq for IpNetwork
[src]
impl PartialEq for IpNetwork
fn eq(&self, other: &IpNetwork) -> bool
[src]
fn eq(&self, other: &IpNetwork) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &IpNetwork) -> bool
[src]
fn ne(&self, other: &IpNetwork) -> bool
This method tests for !=
.
impl Debug for IpNetwork
[src]
impl Debug for IpNetwork
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Hash for IpNetwork
[src]
impl Hash for IpNetwork
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialOrd for IpNetwork
[src]
impl PartialOrd for IpNetwork
fn partial_cmp(&self, other: &IpNetwork) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &IpNetwork) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &IpNetwork) -> bool
[src]
fn lt(&self, other: &IpNetwork) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &IpNetwork) -> bool
[src]
fn le(&self, other: &IpNetwork) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &IpNetwork) -> bool
[src]
fn gt(&self, other: &IpNetwork) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &IpNetwork) -> bool
[src]
fn ge(&self, other: &IpNetwork) -> bool
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]
impl Ord for IpNetwork
fn cmp(&self, other: &IpNetwork) -> Ordering
[src]
fn cmp(&self, other: &IpNetwork) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl FromStr for IpNetwork
[src]
impl FromStr for IpNetwork
type Err = IpNetworkParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<IpNetwork, IpNetworkParseError>
[src]
fn from_str(s: &str) -> Result<IpNetwork, IpNetworkParseError>
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]
impl Display for IpNetwork
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
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]
impl From<Ipv4Network> for IpNetwork
fn from(network: Ipv4Network) -> IpNetwork
[src]
fn from(network: Ipv4Network) -> IpNetwork
Performs the conversion.
impl From<Ipv6Network> for IpNetwork
[src]
impl From<Ipv6Network> for IpNetwork
fn from(network: Ipv6Network) -> IpNetwork
[src]
fn from(network: Ipv6Network) -> IpNetwork
Performs the conversion.