std:🥅:Ipv6Addr - Rust (original) (raw)

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.

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, seeIETF RFC 5952.

use std:🥅: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

impl [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

`pub fn new(

a: u16,
b: u16,
c: u16,
d: u16,
e: u16,
f: u16,
g: u16,
h: u16
) -> 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.

use std:🥅:Ipv6Addr;

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

pub fn [localhost](#method.localhost)() -> [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

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

requires greater scrutiny before stabilization

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

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

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

pub fn [unspecified](#method.unspecified)() -> [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

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

requires greater scrutiny before stabilization

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

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

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

pub fn [segments](#method.segments)(&self) -> [[](../primitive.array.html)[u16](../primitive.u16.html)[; 8]](../primitive.array.html)[src]

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

use std:🥅:Ipv6Addr;

assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).segments(), [0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff]);Run

pub fn [is_unspecified](#method.is%5Funspecified)(&self) -> [bool](../primitive.bool.html)

1.7.0

[src]

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

This property is defined in IETF RFC 4291.

use std:🥅: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

pub fn [is_loopback](#method.is%5Floopback)(&self) -> [bool](../primitive.bool.html)

1.7.0

[src]

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

This property is defined in IETF RFC 4291.

use std:🥅: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

pub fn [is_global](#method.is%5Fglobal)(&self) -> [bool](../primitive.bool.html)[src]

🔬 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:

#![feature(ip)]

use std:🥅: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

pub fn [is_unique_local](#method.is%5Funique%5Flocal)(&self) -> [bool](../primitive.bool.html)[src]

🔬 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.

#![feature(ip)]

use std:🥅: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.

#![feature(ip)]

use std:🥅: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

pub fn [is_unicast_site_local](#method.is%5Funicast%5Fsite%5Flocal)(&self) -> [bool](../primitive.bool.html)[src]

🔬 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).

#![feature(ip)]

use std:🥅: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

pub fn [is_documentation](#method.is%5Fdocumentation)(&self) -> [bool](../primitive.bool.html)[src]

🔬 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.

#![feature(ip)]

use std:🥅: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

pub fn [is_unicast_global](#method.is%5Funicast%5Fglobal)(&self) -> [bool](../primitive.bool.html)[src]

🔬 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:

#![feature(ip)]

use std:🥅: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

pub fn [multicast_scope](#method.multicast%5Fscope)(&self) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[Ipv6MulticastScope](../../std/net/enum.Ipv6MulticastScope.html "enum std:🥅:Ipv6MulticastScope")>[src]

🔬 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.

#![feature(ip)]

use std:🥅:{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

pub fn [is_multicast](#method.is%5Fmulticast)(&self) -> [bool](../primitive.bool.html)

1.7.0

[src]

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

This property is defined by IETF RFC 4291.

use std:🥅: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

pub fn [to_ipv4](#method.to%5Fipv4)(&self) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[Ipv4Addr](../../std/net/struct.Ipv4Addr.html "struct std:🥅:Ipv4Addr")>[src]

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:🥅:{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

pub fn [octets](#method.octets)(&self) -> [[](../primitive.array.html)[u8](../primitive.u8.html)[; 16]](../primitive.array.html)

1.12.0

[src]

Returns the sixteen eight-bit integers the IPv6 address consists of.

use std:🥅: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

impl [Copy](../../std/marker/trait.Copy.html "trait std:📑:Copy") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [From](../../std/convert/trait.From.html "trait std::convert::From")<[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")> for [IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")

1.16.0

[src]

impl [Display](../../std/fmt/trait.Display.html "trait std::fmt::Display") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [Debug](../../std/fmt/trait.Debug.html "trait std::fmt::Debug") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [Clone](../../std/clone/trait.Clone.html "trait std::clone::Clone") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [PartialEq](../../std/cmp/trait.PartialEq.html "trait std::cmp::PartialEq") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [PartialEq](../../std/cmp/trait.PartialEq.html "trait std::cmp::PartialEq")<[IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")> for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")

1.16.0

[src]

fn [eq](../../std/cmp/trait.PartialEq.html#tymethod.eq)(&self, other: &[IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")) -> [bool](../primitive.bool.html)[src]

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

fn [ne](../../std/cmp/trait.PartialEq.html#method.ne)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests for !=.

impl [PartialEq](../../std/cmp/trait.PartialEq.html "trait std::cmp::PartialEq")<[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")> for [IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")

1.16.0

[src]

impl [Eq](../../std/cmp/trait.Eq.html "trait std::cmp::Eq") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [Hash](../../std/hash/trait.Hash.html "trait std::hash::Hash") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [PartialOrd](../../std/cmp/trait.PartialOrd.html "trait std::cmp::PartialOrd") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

fn [partial_cmp](../../std/cmp/trait.PartialOrd.html#tymethod.partial%5Fcmp)(&self, other: &[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[Ordering](../../std/cmp/enum.Ordering.html "enum std::cmp::Ordering")>[src]

This method returns an ordering between self and other values if one exists. Read more

fn [lt](../../std/cmp/trait.PartialOrd.html#method.lt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than (for self and other) and is used by the < operator. Read more

fn [le](../../std/cmp/trait.PartialOrd.html#method.le)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn [gt](../../std/cmp/trait.PartialOrd.html#method.gt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

fn [ge](../../std/cmp/trait.PartialOrd.html#method.ge)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl [PartialOrd](../../std/cmp/trait.PartialOrd.html "trait std::cmp::PartialOrd")<[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")> for [IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")

1.16.0

[src]

fn [partial_cmp](../../std/cmp/trait.PartialOrd.html#tymethod.partial%5Fcmp)(&self, other: &[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[Ordering](../../std/cmp/enum.Ordering.html "enum std::cmp::Ordering")>[src]

This method returns an ordering between self and other values if one exists. Read more

fn [lt](../../std/cmp/trait.PartialOrd.html#method.lt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than (for self and other) and is used by the < operator. Read more

fn [le](../../std/cmp/trait.PartialOrd.html#method.le)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn [gt](../../std/cmp/trait.PartialOrd.html#method.gt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

fn [ge](../../std/cmp/trait.PartialOrd.html#method.ge)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl [PartialOrd](../../std/cmp/trait.PartialOrd.html "trait std::cmp::PartialOrd")<[IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")> for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")

1.16.0

[src]

fn [partial_cmp](../../std/cmp/trait.PartialOrd.html#tymethod.partial%5Fcmp)(&self, other: &[IpAddr](../../std/net/enum.IpAddr.html "enum std:🥅:IpAddr")) -> [Option](../../std/option/enum.Option.html "enum std::option::Option")<[Ordering](../../std/cmp/enum.Ordering.html "enum std::cmp::Ordering")>[src]

This method returns an ordering between self and other values if one exists. Read more

fn [lt](../../std/cmp/trait.PartialOrd.html#method.lt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than (for self and other) and is used by the < operator. Read more

fn [le](../../std/cmp/trait.PartialOrd.html#method.le)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

fn [gt](../../std/cmp/trait.PartialOrd.html#method.gt)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

fn [ge](../../std/cmp/trait.PartialOrd.html#method.ge)(&self, other: [&](../primitive.reference.html)Rhs) -> [bool](../primitive.bool.html)[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl [Ord](../../std/cmp/trait.Ord.html "trait std::cmp::Ord") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [From](../../std/convert/trait.From.html "trait std::convert::From")<[Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")> for [u128](../primitive.u128.html)[src]

impl [From](../../std/convert/trait.From.html "trait std::convert::From")<[u128](../primitive.u128.html)> for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]

impl [From](../../std/convert/trait.From.html "trait std::convert::From")<[[](../primitive.array.html)[u8](../primitive.u8.html)[; 16]](../primitive.array.html)> for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")

1.9.0

[src]

impl [From](../../std/convert/trait.From.html "trait std::convert::From")<[[](../primitive.array.html)[u16](../primitive.u16.html)[; 8]](../primitive.array.html)> for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")

1.16.0

[src]

impl [FromStr](../../std/str/trait.FromStr.html "trait std::str::FromStr") for [Ipv6Addr](../../std/net/struct.Ipv6Addr.html "struct std:🥅:Ipv6Addr")[src]