Enum ip_network::IpNetwork [−][src]
pub enum IpNetwork {
V4(Ipv4Network),
V6(Ipv6Network),
}
Expand description
Holds IPv4 or IPv6 network.
Variants
V4(Ipv4Network)
Tuple Fields of V4
0: Ipv4Network
V6(Ipv6Network)
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);
pub fn new_truncate<I: Into<IpAddr>>(
network_address: I,
netmask: u8
) -> Result<Self, IpNetworkError>
pub fn new_truncate<I: Into<IpAddr>>(
network_address: I,
netmask: u8
) -> Result<Self, IpNetworkError>
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 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.
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
type Expression = Bound<Cidr, Self>
type Expression = Bound<Cidr, Self>
The expression being returned
Perform the conversion
type Expression = Bound<Cidr, Self>
type Expression = Bound<Cidr, Self>
The expression being returned
Perform the conversion
type Expression = Bound<Nullable<Cidr>, Self>
type Expression = Bound<Nullable<Cidr>, Self>
The expression being returned
Perform the conversion
type Expression = Bound<Nullable<Cidr>, Self>
type Expression = Bound<Nullable<Cidr>, Self>
The expression being returned
Perform the conversion
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");
Performs the conversion.
Performs the conversion.
impl<__ST, __DB> FromSqlRow<__ST, __DB> for IpNetwork where
__DB: Backend,
Self: FromSql<__ST, __DB>,
impl<__ST, __DB> FromSqlRow<__ST, __DB> for IpNetwork where
__DB: Backend,
Self: FromSql<__ST, __DB>,
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()));
type Err = IpNetworkParseError
type Err = IpNetworkParseError
The associated error which can be returned from parsing.
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 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 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 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 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
Auto Trait Implementations
impl RefUnwindSafe for IpNetwork
impl UnwindSafe for IpNetwork
Blanket Implementations
Mutably borrows from an owned value. Read more
Returns a reference to self
as a ToSql
trait object.
Convert self
to an expression for Diesel’s query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel’s query builder. Read more