pub struct Ipv6Network { /* private fields */ }ipnetwork only.Expand description
Represents a network range where the IP addresses are of v6
Implementationsยง
Sourceยงimpl Ipv6Network
impl Ipv6Network
Sourcepub const fn new(
addr: Ipv6Addr,
prefix: u8,
) -> Result<Ipv6Network, IpNetworkError>
pub const fn new( addr: Ipv6Addr, prefix: u8, ) -> Result<Ipv6Network, IpNetworkError>
Constructs a new Ipv6Network from any Ipv6Addr and a prefix denoting the network size.
If the prefix is larger than 128 this will return an IpNetworkError::InvalidPrefix.
Sourcepub const fn new_checked(addr: Ipv6Addr, prefix: u8) -> Option<Ipv6Network>
pub const fn new_checked(addr: Ipv6Addr, prefix: u8) -> Option<Ipv6Network>
Constructs a new Ipv6Network from any Ipv6Addr, and a prefix denoting the network size.
If the prefix is larger than 128 this will return None. This is useful in const contexts,
where Option::unwrap may be called to trigger a compile-time error in case the prefix
is an unexpected value.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
const PREFIX: u8 = 64;
const ADDR: Ipv6Addr = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
// Okay!
const NETWORK: Ipv6Network = Ipv6Network::new_checked(ADDR, PREFIX).unwrap();
assert_eq!(NETWORK.prefix(), PREFIX);use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
// Prefix is greater than 128.
const PREFIX: u8 = 128 + 1;
const ADDR: Ipv6Addr = Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0);
// This fails!
const NETWORK: Option<Ipv6Network> = Ipv6Network::new_checked(ADDR, PREFIX);
assert_eq!(NETWORK.unwrap().prefix(), PREFIX);Sourcepub fn with_netmask(
netaddr: Ipv6Addr,
netmask: Ipv6Addr,
) -> Result<Ipv6Network, IpNetworkError>
pub fn with_netmask( netaddr: Ipv6Addr, netmask: Ipv6Addr, ) -> Result<Ipv6Network, IpNetworkError>
Constructs a new Ipv6Network from a network address and a network mask.
If the netmask is not valid this will return an IpNetworkError::InvalidPrefix.
Sourcepub fn iter(&self) -> Ipv6NetworkIterator
pub fn iter(&self) -> Ipv6NetworkIterator
Returns an iterator over Ipv6Network. Each call to next will return the next
Ipv6Addr in the given network. None will be returned when there are no more
addresses.
ยงWarning
This can return up to 2^128 addresses, which will take a long time to iterate over.
pub fn ip(&self) -> Ipv6Addr
pub fn prefix(&self) -> u8
Sourcepub fn is_subnet_of(self, other: Ipv6Network) -> bool
pub fn is_subnet_of(self, other: Ipv6Network) -> bool
Checks if the given Ipv6Network is a subnet of the other.
Sourcepub fn is_supernet_of(self, other: Ipv6Network) -> bool
pub fn is_supernet_of(self, other: Ipv6Network) -> bool
Checks if the given Ipv6Network is a supernet of the other.
Sourcepub fn overlaps(self, other: Ipv6Network) -> bool
pub fn overlaps(self, other: Ipv6Network) -> bool
Checks if the given Ipv6Network is partly contained in other.
Sourcepub fn mask(&self) -> Ipv6Addr
pub fn mask(&self) -> Ipv6Addr
Returns the mask for this Ipv6Network.
That means the prefix most significant bits will be 1 and the rest 0
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "ff01::0".parse().unwrap();
assert_eq!(net.mask(), Ipv6Addr::new(0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff));
let net: Ipv6Network = "ff01::0/32".parse().unwrap();
assert_eq!(net.mask(), Ipv6Addr::new(0xffff, 0xffff, 0, 0, 0, 0, 0, 0));Sourcepub fn network(&self) -> Ipv6Addr
pub fn network(&self) -> Ipv6Addr
Returns the address of the network denoted by this Ipv6Network.
This means the lowest possible IPv6 address inside of the network.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "2001:db8::/96".parse().unwrap();
assert_eq!(net.network(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0));Sourcepub fn broadcast(&self) -> Ipv6Addr
pub fn broadcast(&self) -> Ipv6Addr
Returns the broadcast address of this Ipv6Network.
This means the highest possible IPv4 address inside of the network.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "2001:db8::/96".parse().unwrap();
assert_eq!(net.broadcast(), Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0xffff, 0xffff));Sourcepub fn contains(&self, ip: Ipv6Addr) -> bool
pub fn contains(&self, ip: Ipv6Addr) -> bool
Checks if a given Ipv6Addr is in this Ipv6Network
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "ff01::0/32".parse().unwrap();
assert!(net.contains(Ipv6Addr::new(0xff01, 0, 0, 0, 0, 0, 0, 0x1)));
assert!(!net.contains(Ipv6Addr::new(0xffff, 0, 0, 0, 0, 0, 0, 0x1)));Sourcepub fn size(&self) -> u128
pub fn size(&self) -> u128
Returns number of possible host addresses in this Ipv6Network.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "ff01::0/32".parse().unwrap();
assert_eq!(net.size(), 79228162514264337593543950336);
let tinynet: Ipv6Network = "ff01::0/128".parse().unwrap();
assert_eq!(tinynet.size(), 1);Sourcepub fn nth(self, n: u128) -> Option<Ipv6Addr>
pub fn nth(self, n: u128) -> Option<Ipv6Addr>
Returns the n:th address within this network.
The addresses are indexed from 0 and n must be smaller than the size of the network.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let net: Ipv6Network = "ff01::0/32".parse().unwrap();
assert_eq!(net.nth(0).unwrap(), "ff01::0".parse::<Ipv6Addr>().unwrap());
assert_eq!(net.nth(255).unwrap(), "ff01::ff".parse::<Ipv6Addr>().unwrap());
assert_eq!(net.nth(65538).unwrap(), "ff01::1:2".parse::<Ipv6Addr>().unwrap());
assert!(net.nth(net.size()).is_none());Trait Implementationsยง
Sourceยงimpl Clone for Ipv6Network
impl Clone for Ipv6Network
Sourceยงfn clone(&self) -> Ipv6Network
fn clone(&self) -> Ipv6Network
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSourceยงimpl Debug for Ipv6Network
impl Debug for Ipv6Network
Sourceยงimpl Display for Ipv6Network
impl Display for Ipv6Network
Sourceยงimpl From<Ipv6Addr> for Ipv6Network
impl From<Ipv6Addr> for Ipv6Network
Sourceยงfn from(a: Ipv6Addr) -> Ipv6Network
fn from(a: Ipv6Addr) -> Ipv6Network
Sourceยงimpl From<Ipv6Network> for IpNetwork
impl From<Ipv6Network> for IpNetwork
Sourceยงfn from(v6: Ipv6Network) -> IpNetwork
fn from(v6: Ipv6Network) -> IpNetwork
Sourceยงimpl FromStr for Ipv6Network
Creates an Ipv6Network from parsing a string in CIDR notation.
impl FromStr for Ipv6Network
Creates an Ipv6Network from parsing a string in CIDR notation.
ยงExamples
use std::net::Ipv6Addr;
use ipnetwork::Ipv6Network;
let new = Ipv6Network::new(Ipv6Addr::new(0xff01, 0, 0, 0x17, 0, 0, 0, 0x2), 65).unwrap();
let from_cidr: Ipv6Network = "FF01:0:0:17:0:0:0:2/65".parse().unwrap();
assert_eq!(new.ip(), from_cidr.ip());
assert_eq!(new.prefix(), from_cidr.prefix());Sourceยงtype Err = IpNetworkError
type Err = IpNetworkError
Sourceยงfn from_str(s: &str) -> Result<Ipv6Network, <Ipv6Network as FromStr>::Err>
fn from_str(s: &str) -> Result<Ipv6Network, <Ipv6Network as FromStr>::Err>
s to return a value of this type. Read moreSourceยงimpl Hash for Ipv6Network
impl Hash for Ipv6Network
Sourceยงimpl IntoIterator for &Ipv6Network
impl IntoIterator for &Ipv6Network
Sourceยงimpl Ord for Ipv6Network
impl Ord for Ipv6Network
Sourceยงfn cmp(&self, other: &Ipv6Network) -> Ordering
fn cmp(&self, other: &Ipv6Network) -> Ordering
1.21.0 ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl PartialEq for Ipv6Network
impl PartialEq for Ipv6Network
Sourceยงimpl PartialOrd for Ipv6Network
impl PartialOrd for Ipv6Network
Sourceยงimpl TryFrom<&str> for Ipv6Network
impl TryFrom<&str> for Ipv6Network
Sourceยงtype Error = IpNetworkError
type Error = IpNetworkError
Sourceยงfn try_from(
s: &str,
) -> Result<Ipv6Network, <Ipv6Network as TryFrom<&str>>::Error>
fn try_from( s: &str, ) -> Result<Ipv6Network, <Ipv6Network as TryFrom<&str>>::Error>
impl Copy for Ipv6Network
impl Eq for Ipv6Network
impl StructuralPartialEq for Ipv6Network
Auto Trait Implementationsยง
impl Freeze for Ipv6Network
impl RefUnwindSafe for Ipv6Network
impl Send for Ipv6Network
impl Sync for Ipv6Network
impl Unpin for Ipv6Network
impl UnwindSafe for Ipv6Network
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more