[−][src]Enum ip_network::IpNetwork
Holds IPv4 or IPv6 network.
Variants
V4(Ipv4Network)
V6(Ipv6Network)
Methods
impl IpNetwork
[src]
pub fn new<I: Into<IpAddr>>(
network_address: I,
netmask: u8
) -> Result<Self, IpNetworkError>
[src]
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::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>
[src]
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);
pub fn network_address(&self) -> IpAddr
[src]
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)));
pub fn netmask(&self) -> u8
[src]
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);
pub fn is_ipv4(&self) -> bool
[src]
Returns true
if IpNetwork
contains Ipv4Network
struct.
pub fn is_ipv6(&self) -> bool
[src]
Returns true
if IpNetwork
contains Ipv6Network
struct.
pub fn contains<I: Into<IpAddr>>(&self, ip: I) -> bool
[src]
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)));
pub fn is_default_route(&self) -> bool
[src]
Returns true
if the network is default route, that contains all IP addresses.
pub fn is_multicast(&self) -> bool
[src]
Returns true
if the network is part of multicast network range.
pub fn is_documentation(&self) -> bool
[src]
Returns true
if this is a part of network reserved for documentation.
pub fn is_loopback(&self) -> bool
[src]
Returns true
if this network is inside loopback address range.
pub fn is_global(&self) -> bool
[src]
Returns true
if the network appears to be globally routable.
Trait Implementations
impl Copy for IpNetwork
[src]
impl PartialEq<IpNetwork> for IpNetwork
[src]
impl PartialEq<Ipv4Network> for IpNetwork
[src]
fn eq(&self, other: &Ipv4Network) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<Ipv6Network> for IpNetwork
[src]
fn eq(&self, other: &Ipv6Network) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<IpNetwork> for Ipv4Network
[src]
fn eq(&self, other: &IpNetwork) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<IpNetwork> for Ipv6Network
[src]
fn eq(&self, other: &IpNetwork) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Clone for IpNetwork
[src]
fn clone(&self) -> IpNetwork
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Ord for IpNetwork
[src]
fn cmp(&self, other: &IpNetwork) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl From<Ipv4Addr> for IpNetwork
[src]
impl From<Ipv6Addr> for IpNetwork
[src]
impl From<IpAddr> for IpNetwork
[src]
fn from(ip: IpAddr) -> Self
[src]
Converts IpAddr
to IpNetwork
with netmask 32 for IPv4 address and 128 for IPv6 address.
impl From<Ipv4Network> for IpNetwork
[src]
fn from(network: Ipv4Network) -> Self
[src]
impl From<Ipv6Network> for IpNetwork
[src]
fn from(network: Ipv6Network) -> Self
[src]
impl Eq for IpNetwork
[src]
impl PartialOrd<IpNetwork> for IpNetwork
[src]
fn partial_cmp(&self, other: &IpNetwork) -> Option<Ordering>
[src]
fn lt(&self, other: &IpNetwork) -> bool
[src]
fn le(&self, other: &IpNetwork) -> bool
[src]
fn gt(&self, other: &IpNetwork) -> bool
[src]
fn ge(&self, other: &IpNetwork) -> bool
[src]
impl PartialOrd<Ipv4Network> for IpNetwork
[src]
fn partial_cmp(&self, other: &Ipv4Network) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<IpNetwork> for Ipv4Network
[src]
fn partial_cmp(&self, other: &IpNetwork) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<Ipv6Network> for IpNetwork
[src]
fn partial_cmp(&self, other: &Ipv6Network) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<IpNetwork> for Ipv6Network
[src]
fn partial_cmp(&self, other: &IpNetwork) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Display for IpNetwork
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[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::new(Ipv4Addr::new(192, 168, 1, 0), 24)?); assert_eq!(ip_network.to_string(), "192.168.1.0/24");
impl Debug for IpNetwork
[src]
impl Hash for IpNetwork
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for IpNetwork
[src]
type Err = IpNetworkParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<IpNetwork, IpNetworkParseError>
[src]
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()));
impl<'expr> AsExpression<Cidr> for &'expr IpNetwork
[src]
type Expression = Bound<Cidr, Self>
The expression being returned
fn as_expression(self) -> Self::Expression
[src]
impl<'expr> AsExpression<Nullable<Cidr>> for &'expr IpNetwork
[src]
type Expression = Bound<Nullable<Cidr>, Self>
The expression being returned
fn as_expression(self) -> Self::Expression
[src]
impl AsExpression<Cidr> for IpNetwork
[src]
type Expression = Bound<Cidr, Self>
The expression being returned
fn as_expression(self) -> Self::Expression
[src]
impl AsExpression<Nullable<Cidr>> for IpNetwork
[src]
type Expression = Bound<Nullable<Cidr>, Self>
The expression being returned
fn as_expression(self) -> Self::Expression
[src]
impl<__ST, __DB> Queryable<__ST, __DB> for IpNetwork where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
type Row = Self
The Rust type you'd like to map from. Read more
fn build(row: Self::Row) -> Self
[src]
impl ToSql<Cidr, Pg> for IpNetwork
[src]
impl<__DB> ToSql<Nullable<Cidr>, __DB> for IpNetwork where
__DB: Backend,
Self: ToSql<Cidr, __DB>,
[src]
__DB: Backend,
Self: ToSql<Cidr, __DB>,
impl FromSql<Cidr, Pg> for IpNetwork
[src]
impl<__ST, __DB> FromSqlRow<__ST, __DB> for IpNetwork where
__DB: Backend,
Self: FromSql<__ST, __DB>,
[src]
__DB: Backend,
Self: FromSql<__ST, __DB>,
fn build_from_row<R: Row<__DB>>(row: &mut R) -> Result<Self>
[src]
const FIELDS_NEEDED: usize
[src]
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
impl ToSql for IpNetwork
[src]
fn to_sql(
&self,
t: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
[src]
&self,
t: &Type,
w: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn accepts(ty: &Type) -> bool
fn to_sql_checked(
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
&self,
ty: &Type,
out: &mut Vec<u8>
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
impl FromSql for IpNetwork
[src]
fn from_sql(
t: &Type,
raw: &[u8]
) -> Result<IpNetwork, Box<dyn Error + Sync + Send>>
[src]
t: &Type,
raw: &[u8]
) -> Result<IpNetwork, Box<dyn Error + Sync + Send>>
fn accepts(ty: &Type) -> bool
fn from_sql_null(
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
Creates a new value of this type from a NULL
SQL value. Read more
fn from_sql_nullable(
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
ty: &Type,
raw: Option<&[u8]>
) -> Result<Self, Box<dyn Error + 'static + Sync + Send>>
A convenience function that delegates to from_sql
and from_sql_null
depending on the value of raw
. Read more
impl Serialize for IpNetwork
[src]
impl<'de> Deserialize<'de> for IpNetwork
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> IntoSql for T
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
Self: AsExpression<T>,
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>,
[src]
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more
impl<T> Same for T
type Output = T
Should always be Self
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,