pub struct Ipv6Network { /* fields omitted */ }
IPv4 address length in bits.
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
.
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).unwrap();
assert_eq!(ip_network.network_address(), ip);
assert_eq!(ip_network.netmask(), 32);
Constructs new Ipv6Network
based on Ipv6Addr
and netmask
with truncating host bits
from given network_address
.
Returns error if netmask is bigger than 128.
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).unwrap();
assert_eq!(ip_network.network_address(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0));
assert_eq!(ip_network.netmask(), 32);
Returns network IP address (first address in range).
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).unwrap();
assert_eq!(ip_network.network_address(), ip);
Returns network mask.
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).unwrap();
assert_eq!(ip_network.netmask(), 32);
Returns true
if given IPv6Addr
is inside this network.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 64).unwrap();
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)));
Returns network with smaller netmask by one. If netmask is already zero, None
will be returned.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
let network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap();
assert_eq!(network.supernet(), Some(Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 31).unwrap()));
Returns Ipv6NetworkIterator
over networks with netmask bigger one.
If netmask is already 128, None
will be returned.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap();
let mut iterator = ip_network.subnets().unwrap();
assert_eq!(iterator.next().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 33).unwrap());
assert_eq!(iterator.last().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0x8000, 0, 0, 0, 0, 0), 33).unwrap());
Returns Ipv6NetworkIterator
over networks with defined netmask.
This method panics when prefix is bigger than 128 or when prefix is lower or equal than netmask.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
let network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap();
let mut iterator = network.subnets_with_prefix(33);
assert_eq!(iterator.next().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 33).unwrap());
assert_eq!(iterator.last().unwrap(), Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0x8000, 0, 0, 0, 0, 0), 33).unwrap());
Returns true
for the special 'unspecified' network (::/128).
This property is defined in IETF RFC 4291.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_unspecified());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0), 128).unwrap().is_unspecified());
Returns true
if this is a loopback network (::1/128).
This property is defined in IETF RFC 4291.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1), 128).unwrap().is_loopback());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_loopback());
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
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_global());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1), 128).unwrap().is_global());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1), 128).unwrap().is_global());
Returns true
if this is a part of unique local network (fc00::/7).
This property is defined in IETF RFC 4193.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0), 16).unwrap().is_unique_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().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.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0), 16).unwrap().is_unicast_link_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_unicast_link_local());
Returns true
if this is a deprecated unicast site-local network (fec0::/10).
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0), 16).unwrap().is_unicast_site_local());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_unicast_site_local());
Returns true
if this is a part of network reserved for documentation (2001:db8::/32).
This property is defined in IETF RFC 3849.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap().is_documentation());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_documentation());
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
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(!Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap().is_unicast_global());
assert!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_unicast_global());
Returns true
if this is a part of multicast network (ff00::/8).
This property is defined by IETF RFC 4291.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
assert!(Ipv6Network::new(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0), 8).unwrap().is_multicast());
assert!(!Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().is_multicast());
Returns the network's multicast scope if the network is multicast.
These scopes are defined in IETF RFC 7346.
use std::net::Ipv6Addr;
use ip_network::{Ipv6Network, Ipv6MulticastScope};
assert_eq!(Ipv6Network::new(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0), 32).unwrap().multicast_scope(),
Some(Ipv6MulticastScope::Global));
assert_eq!(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff), 128).unwrap().multicast_scope(), None);
This method returns an Ordering
between self
and other
. Read more
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
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Converts Ipv6Addr
to Ipv6Network
with netmask 128.
Performs copy-assignment from source
. 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 tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
Converts Ipv6Network
to string in format X:X::X/Y (CIDR notation).
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
let ip_network = Ipv6Network::new(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0), 32).unwrap();
assert_eq!(ip_network.to_string(), "2001:db8::/32");
Formats the value using the given formatter. Read more
type Err = IpNetworkParseError
The associated error which can be returned from parsing.
Converts string in format X:X::X/Y (CIDR notation) to Ipv6Network
.
use std::net::Ipv6Addr;
use ip_network::Ipv6Network;
use std::str::FromStr;
let ip_network = Ipv6Network::from_str("2001:db8::/32").unwrap();
assert_eq!(ip_network.network_address(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0));
assert_eq!(ip_network.netmask(), 32);
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
type Owned = T
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static