Struct klickhouse::Ipv6 [−][src]
pub struct Ipv6(pub Ipv6Addr);
Expand description
Wrapper type for Clickhouse IPv6
type.
Methods from Deref<Target = Ipv6Addr>
pub const LOCALHOST: Ipv6Addr
1.30.0[src]
pub const UNSPECIFIED: Ipv6Addr
1.30.0[src]
pub const fn segments(&self) -> [u16; 8]
1.0.0 (const: 1.50.0)[src]
pub const fn segments(&self) -> [u16; 8]
1.0.0 (const: 1.50.0)[src]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]);
pub const fn is_unspecified(&self) -> bool
1.7.0 (const: 1.50.0)[src]
pub const fn is_unspecified(&self) -> bool
1.7.0 (const: 1.50.0)[src]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);
pub const fn is_loopback(&self) -> bool
1.7.0 (const: 1.50.0)[src]
pub const fn is_loopback(&self) -> bool
1.7.0 (const: 1.50.0)[src]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);
pub const fn is_global(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_global(&self) -> bool
[src]ip
)Returns true
if the address appears to be globally routable.
The following return false
:
- the loopback address
- link-local and unique local unicast addresses
- interface-, link-, realm-, admin- and site-local multicast addresses
Examples
#![feature(ip)] use std::net::Ipv6Addr; 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);
pub const fn is_unique_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_unique_local(&self) -> bool
[src]ip
)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; 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);
pub const fn is_unicast_link_local_strict(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_unicast_link_local_strict(&self) -> bool
[src]ip
)Returns true
if the address is a unicast link-local address (fe80::/64
).
A common misconception is to think that “unicast link-local addresses start with
fe80::
”, but IETF RFC 4291 actually defines a stricter format for these addresses:
| 10 |
| bits | 54 bits | 64 bits |
+----------+-------------------------+----------------------------+
|1111111010| 0 | interface ID |
+----------+-------------------------+----------------------------+
This method validates the format defined in the RFC and won’t recognize addresses
like fe80:0:0:1::
or fe81::
as unicast link-local addresses.
If you need a less strict validation, use Ipv6Addr::is_unicast_link_local()
instead.
Examples
#![feature(ip)] use std::net::Ipv6Addr; let ip = Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0); assert!(ip.is_unicast_link_local_strict()); let ip = Ipv6Addr::new(0xfe80, 0, 0, 0, 0xffff, 0xffff, 0xffff, 0xffff); assert!(ip.is_unicast_link_local_strict()); let ip = Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0); assert!(!ip.is_unicast_link_local_strict()); assert!(ip.is_unicast_link_local()); let ip = Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0); assert!(!ip.is_unicast_link_local_strict()); assert!(ip.is_unicast_link_local());
See also
- IETF RFC 4291 section 2.5.6
- RFC 4291 errata 4406 (which has been rejected but provides useful insight)
Ipv6Addr::is_unicast_link_local()
pub const fn is_unicast_link_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_unicast_link_local(&self) -> bool
[src]ip
)Returns true
if the address is a unicast link-local address (fe80::/10
).
This method returns true
for addresses in the range reserved by [RFC 4291 section 2.4],
i.e. addresses with the following format:
| 10 |
| bits | 54 bits | 64 bits |
+----------+-------------------------+----------------------------+
|1111111010| arbitratry value | interface ID |
+----------+-------------------------+----------------------------+
As a result, this method considers addresses such as fe80:0:0:1::
or fe81::
to be
unicast link-local addresses, whereas Ipv6Addr::is_unicast_link_local_strict()
does not.
If you need a strict validation fully compliant with the RFC, use
Ipv6Addr::is_unicast_link_local_strict()
instead.
Examples
#![feature(ip)] use std::net::Ipv6Addr; let ip = Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0); assert!(ip.is_unicast_link_local()); let ip = Ipv6Addr::new(0xfe80, 0, 0, 0, 0xffff, 0xffff, 0xffff, 0xffff); assert!(ip.is_unicast_link_local()); let ip = Ipv6Addr::new(0xfe80, 0, 0, 1, 0, 0, 0, 0); assert!(ip.is_unicast_link_local()); assert!(!ip.is_unicast_link_local_strict()); let ip = Ipv6Addr::new(0xfe81, 0, 0, 0, 0, 0, 0, 0); assert!(ip.is_unicast_link_local()); assert!(!ip.is_unicast_link_local_strict());
See also
- IETF RFC 4291 section 2.4
- RFC 4291 errata 4406 (which has been rejected but provides useful insight)
pub const fn is_unicast_site_local(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_unicast_site_local(&self) -> bool
[src]ip
)Returns true
if this is a deprecated unicast site-local address (fec0::/10). The
unicast site-local address format is defined in RFC 4291 section 2.5.7 as:
| 10 |
| bits | 54 bits | 64 bits |
+----------+-------------------------+----------------------------+
|1111111011| subnet ID | interface ID |
+----------+-------------------------+----------------------------+
Examples
#![feature(ip)] use std::net::Ipv6Addr; 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);
Warning
As per RFC 3879, the whole FEC0::/10
prefix is
deprecated. New software must not support site-local
addresses.
pub const fn is_documentation(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_documentation(&self) -> bool
[src]ip
)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; 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);
pub const fn is_unicast_global(&self) -> bool
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn is_unicast_global(&self) -> bool
[src]ip
)Returns true
if the address is a globally routable unicast address.
The following return false:
- the loopback address
- the link-local addresses
- unique local addresses
- the unspecified address
- the address range reserved for documentation
This method returns true
for site-local addresses as per RFC 4291 section 2.5.7
The special behavior of [the site-local unicast] prefix defined in [RFC3513] must no longer
be supported in new implementations (i.e., new implementations must treat this prefix as
Global Unicast).
Examples
#![feature(ip)] use std::net::Ipv6Addr; 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);
pub const fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn multicast_scope(&self) -> Option<Ipv6MulticastScope>
[src]ip
)Returns the address’s multicast scope if the address is multicast.
Examples
#![feature(ip)] use std::net::{Ipv6Addr, Ipv6MulticastScope}; 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);
pub const fn is_multicast(&self) -> bool
1.7.0 (const: 1.50.0)[src]
pub const fn is_multicast(&self) -> bool
1.7.0 (const: 1.50.0)[src]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);
pub const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr>
[src]
🔬 This is a nightly-only experimental API. (ip
)
pub const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr>
[src]ip
)Converts this address to an IPv4
address if it’s an “IPv4-mapped IPv6 address”
defined in IETF RFC 4291 section 2.5.5.2, otherwise returns None
.
::ffff:a.b.c.d
becomes a.b.c.d
.
All addresses not starting with ::ffff
will return None
.
Examples
#![feature(ip)] use std::net::{Ipv4Addr, Ipv6Addr}; assert_eq!(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0).to_ipv4_mapped(), None); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0xc00a, 0x2ff).to_ipv4_mapped(), Some(Ipv4Addr::new(192, 10, 2, 255))); assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
pub const fn to_ipv4(&self) -> Option<Ipv4Addr>
1.0.0 (const: 1.50.0)[src]
pub const fn to_ipv4(&self) -> Option<Ipv4Addr>
1.0.0 (const: 1.50.0)[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
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)));
Trait Implementations
impl Ord for Ipv6
[src]
impl Ord for Ipv6
[src]impl PartialOrd<Ipv6> for Ipv6
[src]
impl PartialOrd<Ipv6> for Ipv6
[src]fn partial_cmp(&self, other: &Ipv6) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Ipv6) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Ipv6
[src]
impl Eq for Ipv6
[src]
impl StructuralEq for Ipv6
[src]
impl StructuralPartialEq for Ipv6
[src]
Auto Trait Implementations
impl RefUnwindSafe for Ipv6
impl Send for Ipv6
impl Sync for Ipv6
impl Unpin for Ipv6
impl UnwindSafe for Ipv6
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
pub fn equivalent(&self, key: &K) -> bool
[src]Compare self to key
and return true
if they are equal.
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more