[][src]Struct ip_network::Ipv6Network

pub struct Ipv6Network { /* fields omitted */ }

IPv6 Network.

Methods

impl Ipv6Network[src]

pub const LENGTH: u8[src]

IPv4 address length in bits.

pub fn new(
    network_address: Ipv6Addr,
    netmask: u8
) -> Result<Self, IpNetworkError>
[src]

Constructs new Ipv6Network based on Ipv6Addr and netmask.

Returns error if netmask is bigger than 128 or if host bits are set in network_address.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
let ip_network = Ipv6Network::new(ip, 32)?;
assert_eq!(ip_network.network_address(), ip);
assert_eq!(ip_network.netmask(), 32);

pub fn new_truncate(
    network_address: Ipv6Addr,
    netmask: u8
) -> Result<Self, IpNetworkError>
[src]

Constructs new Ipv6Network based on Ipv6Addr and netmask with truncating host bits from given network_address.

Returns error if netmask is bigger than 128.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 1, 0, 0);
let ip_network = Ipv6Network::new_truncate(ip, 32)?;
assert_eq!(ip_network.network_address(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0));
assert_eq!(ip_network.netmask(), 32);

pub fn network_address(&self) -> Ipv6Addr[src]

Returns network IP address (first address in range).

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
let ip_network = Ipv6Network::new(ip, 32)?;
assert_eq!(ip_network.network_address(), ip);

pub fn netmask(&self) -> u8[src]

Returns network mask.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
let ip_network = Ipv6Network::new(ip, 32)?;
assert_eq!(ip_network.netmask(), 32);

pub fn contains(&self, ip: Ipv6Addr) -> bool[src]

Returns true if given IPv6Addr is inside this network.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 64)?;
assert!(ip_network.contains(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 1)));
assert!(!ip_network.contains(Ipv6Addr::new(0x2001, 0xdb9, 0, 0, 0, 0, 0, 0)));

pub fn supernet(&self) -> Option<Self>[src]

Returns network with smaller netmask by one. If netmask is already zero, None will be returned.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?;
assert_eq!(network.supernet(), Some(Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 31)?));

Important traits for Ipv6NetworkIterator
pub fn subnets(&self) -> Ipv6NetworkIterator[src]

Returns Ipv6NetworkIterator over networks with netmask bigger one. If netmask is already 128, empty iterator will be returned.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?;
let mut iterator = ip_network.subnets();
assert_eq!(iterator.next().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 33)?);
assert_eq!(iterator.last().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0x8000, 0, 0, 0, 0, 0), 33)?);

Important traits for Ipv6NetworkIterator
pub fn subnets_with_prefix(&self, prefix: u8) -> Ipv6NetworkIterator[src]

Returns Ipv6NetworkIterator over networks with defined netmask. Because len() method returns usize and number of networks can be bigger than usize, you can use real_len() method to get exact number of networks.

Panics

This method panics when prefix is bigger than 128 or when prefix is lower or equal than netmask.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?;
let mut iterator = network.subnets_with_prefix(33);
assert_eq!(2, iterator.real_len());
assert_eq!(iterator.next().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 33)?);
assert_eq!(iterator.last().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0x8000, 0, 0, 0, 0, 0), 33)?);

pub fn is_default_route(&self) -> bool[src]

Returns true for the default route network (::/0), that contains all IPv6 addresses.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0), 0)?.is_default_route());

pub fn is_unspecified(&self) -> bool[src]

Returns true for the special 'unspecified' network (::/128).

This property is defined in IETF RFC 4291.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_unspecified());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0), 128)?.is_unspecified());

pub fn is_loopback(&self) -> bool[src]

Returns true if this is a loopback network (::1/128).

This property is defined in IETF RFC 4291.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1), 128)?.is_loopback());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_loopback());

pub fn is_global(&self) -> bool[src]

Returns true if the address appears to be globally routable.

The following return false:

  • the loopback network
  • link-local, site-local, and unique local unicast networks
  • interface-, link-, realm-, admin- and site-local multicast networks

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_global());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1), 128)?.is_global());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1), 128)?.is_global());

pub fn is_unique_local(&self) -> bool[src]

Returns true if this is a part of unique local network (fc00::/7).

This property is defined in IETF RFC 4193.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0), 16)?.is_unique_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_unique_local());

Returns true if the network is part of unicast and link-local (fe80::/10).

This property is defined in IETF RFC 4291.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0), 16)?.is_unicast_link_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_unicast_link_local());

pub fn is_unicast_site_local(&self) -> bool[src]

Returns true if this is a deprecated unicast site-local network (fec0::/10).

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0), 16)?.is_unicast_site_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_unicast_site_local());

pub fn is_documentation(&self) -> bool[src]

Returns true if this is a part of network reserved for documentation (2001:db8::/32).

This property is defined in IETF RFC 3849.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?.is_documentation());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_documentation());

pub fn is_unicast_global(&self) -> bool[src]

Returns true if the network is a globally routable unicast network.

The following return false:

  • the loopback network
  • the link-local network
  • the (deprecated) site-local network
  • unique local network
  • the unspecified network
  • the network range reserved for documentation

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(!Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?.is_unicast_global());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_unicast_global());

pub fn is_multicast(&self) -> bool[src]

Returns true if this is a part of multicast network (ff00::/8).

This property is defined by IETF RFC 4291.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

assert!(Ipv6Network::new(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0), 8)?.is_multicast());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.is_multicast());

pub fn multicast_scope(&self) -> Option<Ipv6MulticastScope>[src]

Returns the network's multicast scope if the network is multicast.

These scopes are defined in IETF RFC 7346.

Examples

use std::net::Ipv6Addr;
use ip_network::{Ipv6Network, Ipv6MulticastScope};

assert_eq!(Ipv6Network::new(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0), 32)?.multicast_scope(),
                             Some(Ipv6MulticastScope::Global));
assert_eq!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128)?.multicast_scope(), None);

Trait Implementations

impl Copy for Ipv6Network[src]

impl PartialEq<Ipv6Network> for IpNetwork[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl PartialEq<IpNetwork> for Ipv6Network[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl PartialEq<Ipv6Network> for Ipv6Network[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Clone for Ipv6Network[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Ord for Ipv6Network[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]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl From<Ipv6Network> for IpNetwork[src]

impl From<Ipv6Addr> for Ipv6Network[src]

fn from(ip: Ipv6Addr) -> Self[src]

Converts Ipv6Addr to Ipv6Network with netmask 128.

impl Eq for Ipv6Network[src]

impl PartialOrd<Ipv6Network> for IpNetwork[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]

#[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 Ipv6Network[src]

impl Display for Ipv6Network[src]

fn fmt(&self, f: &mut Formatter) -> Result[src]

Converts Ipv6Network to string in format X:X::X/Y (CIDR notation).

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;

let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32)?;
assert_eq!(ip_network.to_string(), "2001:db8::/32");

impl Debug for Ipv6Network[src]

impl Hash for Ipv6Network[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

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

impl FromStr for Ipv6Network[src]

type Err = IpNetworkParseError

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Ipv6Network, IpNetworkParseError>[src]

Converts string in format X:X::X/Y (CIDR notation) to Ipv6Network.

Examples

use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
use std::str::FromStr;

let ip_network = Ipv6Network::from_str("2001:db8::/32")?;
assert_eq!(ip_network.network_address(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0));
assert_eq!(ip_network.netmask(), 32);

impl<'expr> AsExpression<Cidr> for &'expr Ipv6Network[src]

type Expression = Bound<Cidr, Self>

The expression being returned

impl<'expr> AsExpression<Nullable<Cidr>> for &'expr Ipv6Network[src]

type Expression = Bound<Nullable<Cidr>, Self>

The expression being returned

impl AsExpression<Cidr> for Ipv6Network[src]

type Expression = Bound<Cidr, Self>

The expression being returned

impl AsExpression<Nullable<Cidr>> for Ipv6Network[src]

type Expression = Bound<Nullable<Cidr>, Self>

The expression being returned

impl<__ST, __DB> Queryable<__ST, __DB> for Ipv6Network where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

type Row = Self

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

impl ToSql<Cidr, Pg> for Ipv6Network[src]

impl<__DB> ToSql<Nullable<Cidr>, __DB> for Ipv6Network where
    __DB: Backend,
    Self: ToSql<Cidr, __DB>, 
[src]

impl FromSql<Cidr, Pg> for Ipv6Network[src]

impl<__ST, __DB> FromSqlRow<__ST, __DB> for Ipv6Network where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[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 Ipv6Network[src]

impl FromSql for Ipv6Network[src]

fn from_sql_null(
    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>>

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

impl Serialize for Ipv6Network[src]

impl<'de> Deserialize<'de> for Ipv6Network[src]

Auto Trait Implementations

impl Send for Ipv6Network

impl Sync for Ipv6Network

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> IntoSql for T[src]

fn into_sql<T>(self) -> Self::Expression where
    Self: AsExpression<T>, 
[src]

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]

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]