Struct std::net::Ipv6Addr1.0.0 [] [src]

pub struct Ipv6Addr { /* fields omitted */ }

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.

The size of an Ipv6Addr struct may vary depending on the target operating system.

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 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);Run

Methods

impl Ipv6Addr
[src]

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 std::net::Ipv6Addr;

let addr = Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff);Run

🔬 This is a nightly-only experimental API. (ip_constructors #44582)

requires greater scrutiny before stabilization

Creates a new IPv6 address representing localhost: ::1.

Examples

#![feature(ip_constructors)]
use std::net::Ipv6Addr;

let addr = Ipv6Addr::localhost();
assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));Run

🔬 This is a nightly-only experimental API. (ip_constructors #44582)

requires greater scrutiny before stabilization

Creates a new IPv6 address representing the unspecified address: ::

Examples

#![feature(ip_constructors)]
use std::net::Ipv6Addr;

let addr = Ipv6Addr::unspecified();
assert_eq!(addr, Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0));Run

Returns the eight 16-bit segments that make up this address.

Examples

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]);Run

Returns true for the special 'unspecified' address (::).

This property is defined in IETF RFC 4291.

Examples

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);Run

Returns true if this is a loopback address (::1).

This property is defined in IETF RFC 4291.

Examples

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);Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

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

#![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);
}Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

Returns true if this is a unique local address (fc00::/7).

This property is defined in IETF RFC 4193.

Examples

#![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);
}Run
🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

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

This property is defined in IETF RFC 4291.

Examples

#![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);
}Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

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

Examples

#![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);
}Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

Returns true if this is an address reserved for documentation (2001:db8::/32).

This property is defined in IETF RFC 3849.

Examples

#![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);
}Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

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

#![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);
}Run

🔬 This is a nightly-only experimental API. (ip #27709)

extra functionality has not been scrutinized to the level that it should be to be stable

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

Examples

#![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);
}Run

Returns true if this is a multicast address (ff00::/8).

This property is defined by IETF RFC 4291.

Examples

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);Run

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 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)));Run

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]);Run

Trait Implementations

impl Copy for Ipv6Addr
[src]

impl From<Ipv6Addr> for IpAddr
1.16.0
[src]

Performs the conversion.

impl Display for Ipv6Addr
[src]

Formats the value using the given formatter. Read more

impl Debug for Ipv6Addr
[src]

Formats the value using the given formatter. Read more

impl Clone for Ipv6Addr
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for Ipv6Addr
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<IpAddr> for Ipv6Addr
1.16.0
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<Ipv6Addr> for IpAddr
1.16.0
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for Ipv6Addr
[src]

impl Hash for Ipv6Addr
[src]

Feeds this value into the given [Hasher]. Read more

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

impl PartialOrd for Ipv6Addr
[src]

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

impl PartialOrd<Ipv6Addr> for IpAddr
1.16.0
[src]

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

impl PartialOrd<IpAddr> for Ipv6Addr
1.16.0
[src]

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

impl Ord for Ipv6Addr
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl From<Ipv6Addr> for u128
1.26.0
[src]

Performs the conversion.

impl From<u128> for Ipv6Addr
1.26.0
[src]

Performs the conversion.

impl From<[u8; 16]> for Ipv6Addr
1.9.0
[src]

Performs the conversion.

impl From<[u16; 8]> for Ipv6Addr
1.16.0
[src]

Performs the conversion.

impl FromStr for Ipv6Addr
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

impl Send for Ipv6Addr

impl Sync for Ipv6Addr