Struct embedded_nal_async::Ipv6Addr
source · [−]pub struct Ipv6Addr { /* private fields */ }Expand description
An IPv6 address.
IPv6 addresses are defined as 128-bit integers in IETF RFC 4291. They are usually represented as eight 16-bit segments.
See IpAddr for a type encompassing both IPv4 and IPv6 addresses.
Textual representation
Ipv6Addr provides a FromStr implementation. There are many ways to represent
an IPv6 address in text, but in general, each segments is written in hexadecimal
notation, and segments are separated by :. For more information, see
IETF RFC 5952.
Examples
use no_std_net::Ipv6Addr;
let localhost = Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1);
assert_eq!("::1".parse(), Ok(localhost));
assert_eq!(localhost.is_loopback(), true);Implementations
sourceimpl Ipv6Addr
impl Ipv6Addr
sourcepub const fn new(
a: u16,
b: u16,
c: u16,
d: u16,
e: u16,
f: u16,
g: u16,
h: u16
) -> Ipv6Addr
pub const fn new(
a: u16,
b: u16,
c: u16,
d: u16,
e: u16,
f: u16,
g: u16,
h: u16
) -> Ipv6Addr
Creates a new IPv6 address from eight 16-bit segments.
The result will represent the IP address a:b:c:d:e:f:g:h.
Examples
use no_std_net::Ipv6Addr;
let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);sourcepub const fn localhost() -> Ipv6Addr
pub const fn localhost() -> Ipv6Addr
Creates a new IPv6 address representing localhost: ::1.
Examples
use no_std_net::Ipv6Addr;
let addr = Ipv6Addr::localhost();
assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));sourcepub const fn unspecified() -> Ipv6Addr
pub const fn unspecified() -> Ipv6Addr
Creates a new IPv6 address representing the unspecified address: ::
Examples
use no_std_net::Ipv6Addr;
let addr = Ipv6Addr::unspecified();
assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));sourcepub const fn first_segment(&self) -> u16
pub const fn first_segment(&self) -> u16
Returns the first 16-bit segment that makes up this address.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0x0011, 0x2233, 0, 0, 0, 0, 0, 0).first_segment(), 0x11);sourcepub const fn second_segment(&self) -> u16
pub const fn second_segment(&self) -> u16
Returns the second 16-bit segment that makes up this address.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0x0011, 0x2233, 0, 0, 0, 0, 0, 0).second_segment(), 0x2233);sourcepub const fn segments(&self) -> [u16; 8]
pub const fn segments(&self) -> [u16; 8]
Returns the eight 16-bit segments that make up this address.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(),
[0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]);sourcepub const fn is_unspecified(&self) -> bool
pub const fn is_unspecified(&self) -> bool
Returns true for the special ‘unspecified’ address (::).
This property is defined in IETF RFC 4291.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unspecified(), false);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0).is_unspecified(), true);sourcepub const fn is_loopback(&self) -> bool
pub const fn is_loopback(&self) -> bool
Returns true if this is a loopback address (::1).
This property is defined in IETF RFC 4291.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_loopback(), false);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_loopback(), true);sourcepub const fn is_global(&self) -> bool
pub const fn is_global(&self) -> bool
Returns true if the address appears to be globally routable.
The following return false:
- the loopback address
- link-local, site-local, and unique local unicast addresses
- interface-, link-, realm-, admin- and site-local multicast addresses
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_global(), true);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1).is_global(), false);
assert_eq!(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1).is_global(), true);
}sourcepub const fn is_unique_local(&self) -> bool
pub const fn is_unique_local(&self) -> bool
Returns true if this is a unique local address (fc00::/7).
This property is defined in IETF RFC 4193.
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unique_local(),
false);
assert_eq!(Ipv6Addr::new(0xfc02, 0, 0, 0, 0, 0, 0, 0).is_unique_local(), true);
}sourcepub const fn is_unicast_link_local(&self) -> bool
pub const fn is_unicast_link_local(&self) -> bool
Returns true if the address is unicast and link-local (fe80::/10).
This property is defined in IETF RFC 4291.
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_link_local(),
false);
assert_eq!(Ipv6Addr::new(0xfe8a, 0, 0, 0, 0, 0, 0, 0).is_unicast_link_local(), true);
}sourcepub const fn is_unicast_site_local(&self) -> bool
pub const fn is_unicast_site_local(&self) -> bool
Returns true if this is a deprecated unicast site-local address
(fec0::/10).
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_site_local(),
false);
assert_eq!(Ipv6Addr::new(0xfec2, 0, 0, 0, 0, 0, 0, 0).is_unicast_site_local(), true);
}sourcepub const fn is_documentation(&self) -> bool
pub const fn is_documentation(&self) -> bool
Returns true if this is an address reserved for documentation
(2001:db8::/32).
This property is defined in IETF RFC 3849.
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_documentation(),
false);
assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_documentation(), true);
}sourcepub const fn is_unicast_global(&self) -> bool
pub const fn is_unicast_global(&self) -> bool
Returns true if the address is a globally routable unicast address.
The following return false:
- the loopback address
- the link-local addresses
- the (deprecated) site-local addresses
- unique local addresses
- the unspecified address
- the address range reserved for documentation
Examples
use no_std_net::Ipv6Addr;
fn main() {
assert_eq!(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0).is_unicast_global(), false);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_unicast_global(),
true);
}sourcepub const fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
pub const fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
Returns the address’s multicast scope if the address is multicast.
Examples
use no_std_net::{Ipv6Addr, Ipv6MulticastScope};
fn main() {
assert_eq!(Ipv6Addr::new(0xff0e, 0, 0, 0, 0, 0, 0, 0).multicast_scope(),
Some(Ipv6MulticastScope::Global));
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).multicast_scope(), None);
}sourcepub const fn is_multicast(&self) -> bool
pub const fn is_multicast(&self) -> bool
Returns true if this is a multicast address (ff00::/8).
This property is defined by IETF RFC 4291.
Examples
use no_std_net::Ipv6Addr;
assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).is_multicast(), true);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).is_multicast(), false);sourcepub const fn to_ipv4(&self) -> Option<Ipv4Addr>
pub const fn to_ipv4(&self) -> Option<Ipv4Addr>
Converts this address to an IPv4 address. Returns None if this address is
neither IPv4-compatible or IPv4-mapped.
::a.b.c.d and ::ffff:a.b.c.d become a.b.c.d
Examples
use no_std_net::{Ipv4Addr, Ipv6Addr};
assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4(), None);
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4(),
Some(Ipv4Addr::new(192, 10, 2, 255)));
assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4(),
Some(Ipv4Addr::new(0, 0, 0, 1)));Trait Implementations
sourceimpl From<[u16; 8]> for Ipv6Addr
impl From<[u16; 8]> for Ipv6Addr
sourcefn from(segments: [u16; 8]) -> Ipv6Addr
fn from(segments: [u16; 8]) -> Ipv6Addr
Creates an Ipv6Addr from an eight element 16-bit array.
Examples
use no_std_net::Ipv6Addr;
let addr = Ipv6Addr::from([
525u16, 524u16, 523u16, 522u16,
521u16, 520u16, 519u16, 518u16,
]);
assert_eq!(
Ipv6Addr::new(
0x20d, 0x20c,
0x20b, 0x20a,
0x209, 0x208,
0x207, 0x206
),
addr
);sourceimpl From<[u8; 16]> for Ipv6Addr
impl From<[u8; 16]> for Ipv6Addr
sourcefn from(octets: [u8; 16]) -> Ipv6Addr
fn from(octets: [u8; 16]) -> Ipv6Addr
Creates an Ipv6Addr from a sixteen element byte array.
Examples
use no_std_net::Ipv6Addr;
let addr = Ipv6Addr::from([
25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8,
17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8,
]);
assert_eq!(
Ipv6Addr::new(
0x1918, 0x1716,
0x1514, 0x1312,
0x1110, 0x0f0e,
0x0d0c, 0x0b0a
),
addr
);sourceimpl Ord for Ipv6Addr
impl Ord for Ipv6Addr
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<IpAddr> for Ipv6Addr
impl PartialOrd<IpAddr> for Ipv6Addr
sourcefn partial_cmp(&self, other: &IpAddr) -> Option<Ordering>
fn partial_cmp(&self, other: &IpAddr) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl PartialOrd<Ipv6Addr> for IpAddr
impl PartialOrd<Ipv6Addr> for IpAddr
sourcefn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl PartialOrd<Ipv6Addr> for Ipv6Addr
impl PartialOrd<Ipv6Addr> for Ipv6Addr
sourcefn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Copy for Ipv6Addr
impl Eq for Ipv6Addr
impl StructuralEq for Ipv6Addr
impl StructuralPartialEq for Ipv6Addr
Auto Trait Implementations
impl RefUnwindSafe for Ipv6Addr
impl Send for Ipv6Addr
impl Sync for Ipv6Addr
impl Unpin for Ipv6Addr
impl UnwindSafe for Ipv6Addr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more