pub struct Ipv6Addr { /* fields omitted */ }
Representation of an IPv6 address.
impl Ipv6Addr
[src]
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.
use std::net::Ipv6Addr; let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);
fn segments(&self) -> [u16; 8]
Returns the eight 16-bit segments that make up this address.
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(), [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]);
fn is_unspecified(&self) -> bool
Returns true for the special 'unspecified' address (::).
This property is defined in RFC 4291.
use 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);
fn is_loopback(&self) -> bool
Returns true if this is a loopback address (::1).
This property is defined in RFC 4291.
use 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);
fn is_global(&self) -> bool
Returns true if the address appears to be globally routable.
The following return false:
#![feature(ip)] use 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); }
fn is_unique_local(&self) -> bool
Returns true if this is a unique local address (fc00::/7).
This property is defined in RFC 4193.
#![feature(ip)] use 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); }
fn is_unicast_link_local(&self) -> bool
Returns true if the address is unicast and link-local (fe80::/10).
This property is defined in RFC 4291.
#![feature(ip)] use 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); }
fn is_unicast_site_local(&self) -> bool
Returns true if this is a deprecated unicast site-local address (fec0::/10).
#![feature(ip)] use 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); }
fn is_documentation(&self) -> bool
Returns true if this is an address reserved for documentation (2001:db8::/32).
This property is defined in RFC 3849.
#![feature(ip)] use 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); }
fn is_unicast_global(&self) -> bool
Returns true if the address is a globally routable unicast address.
The following return false:
#![feature(ip)] use 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); }
fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
Returns the address's multicast scope if the address is multicast.
#![feature(ip)] use 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); }
fn is_multicast(&self) -> bool
Returns true if this is a multicast address (ff00::/8).
This property is defined by RFC 4291.
use 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);
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
use 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)));
fn octets(&self) -> [u8; 16]
Returns the sixteen eight-bit integers the IPv6 address consists of.
use std::net::Ipv6Addr; assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).octets(), [255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
impl Copy for Ipv6Addr
[src]
impl Display for Ipv6Addr
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result
Formats the value using the given formatter.
impl Debug for Ipv6Addr
[src]
fn fmt(&self, fmt: &mut Formatter) -> Result
Formats the value using the given formatter.
impl Clone for Ipv6Addr
[src]
fn clone(&self) -> Ipv6Addr
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl PartialEq for Ipv6Addr
[src]
fn eq(&self, other: &Ipv6Addr) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<IpAddr> for Ipv6Addr
fn eq(&self, other: &IpAddr) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Eq for Ipv6Addr
[src]
impl Hash for Ipv6Addr
[src]
fn hash<H: Hasher>(&self, s: &mut H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
Feeds a slice of this type into the state provided.
impl PartialOrd for Ipv6Addr
[src]
fn partial_cmp(&self, other: &Ipv6Addr) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
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
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<IpAddr> for Ipv6Addr
fn partial_cmp(&self, other: &IpAddr) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
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
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for Ipv6Addr
[src]
fn cmp(&self, other: &Ipv6Addr) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl From<[u8; 16]> for Ipv6Addr
fn from(octets: [u8; 16]) -> Ipv6Addr
Performs the conversion.
impl From<[u16; 8]> for Ipv6Addr
fn from(segments: [u16; 8]) -> Ipv6Addr
Performs the conversion.
impl FromStr for Ipv6Addr
[src]
type Err = AddrParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Ipv6Addr, AddrParseError>
Parses a string s
to return a value of this type. Read more
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/net/struct.Ipv6Addr.html