Rollup merge of #38077 - GuillaumeGomez:ipaddr_doc, r=frewsxcv
Add missing examples for IpAddr enum r? @frewsxcv
This commit is contained in:
commit
d68c585b01
@ -79,8 +79,18 @@ pub enum Ipv6MulticastScope {
|
||||
|
||||
impl IpAddr {
|
||||
/// Returns true for the special 'unspecified' address ([IPv4], [IPv6]).
|
||||
///
|
||||
/// [IPv4]: ../../std/net/struct.Ipv4Addr.html#method.is_unspecified
|
||||
/// [IPv6]: ../../std/net/struct.Ipv6Addr.html#method.is_unspecified
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)).is_unspecified(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)).is_unspecified(), true);
|
||||
/// ```
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
pub fn is_unspecified(&self) -> bool {
|
||||
match *self {
|
||||
@ -90,8 +100,18 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if this is a loopback address ([IPv4], [IPv6]).
|
||||
///
|
||||
/// [IPv4]: ../../std/net/struct.Ipv4Addr.html#method.is_loopback
|
||||
/// [IPv6]: ../../std/net/struct.Ipv6Addr.html#method.is_loopback
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).is_loopback(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0x1)).is_loopback(), true);
|
||||
/// ```
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
pub fn is_loopback(&self) -> bool {
|
||||
match *self {
|
||||
@ -101,8 +121,23 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if the address appears to be globally routable ([IPv4], [IPv6]).
|
||||
///
|
||||
/// [IPv4]: ../../std/net/struct.Ipv4Addr.html#method.is_global
|
||||
/// [IPv6]: ../../std/net/struct.Ipv6Addr.html#method.is_global
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ip)]
|
||||
///
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(80, 9, 12, 3)).is_global(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0x1c9, 0, 0, 0xafc8, 0, 0x1)).is_global(),
|
||||
/// true);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn is_global(&self) -> bool {
|
||||
match *self {
|
||||
IpAddr::V4(ref a) => a.is_global(),
|
||||
@ -111,8 +146,18 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if this is a multicast address ([IPv4], [IPv6]).
|
||||
///
|
||||
/// [IPv4]: ../../std/net/struct.Ipv4Addr.html#method.is_multicast
|
||||
/// [IPv6]: ../../std/net/struct.Ipv6Addr.html#method.is_multicast
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(224, 254, 0, 0)).is_multicast(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0xff00, 0, 0, 0, 0, 0, 0, 0)).is_multicast(), true);
|
||||
/// ```
|
||||
#[stable(feature = "ip_shared", since = "1.12.0")]
|
||||
pub fn is_multicast(&self) -> bool {
|
||||
match *self {
|
||||
@ -122,8 +167,23 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if this address is in a range designated for documentation ([IPv4], [IPv6]).
|
||||
///
|
||||
/// [IPv4]: ../../std/net/struct.Ipv4Addr.html#method.is_documentation
|
||||
/// [IPv6]: ../../std/net/struct.Ipv6Addr.html#method.is_documentation
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ip)]
|
||||
///
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_documentation(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0))
|
||||
/// .is_documentation(), true);
|
||||
/// }
|
||||
/// ```
|
||||
pub fn is_documentation(&self) -> bool {
|
||||
match *self {
|
||||
IpAddr::V4(ref a) => a.is_documentation(),
|
||||
@ -132,6 +192,20 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if this address is a valid IPv4 address, false if it's a valid IPv6 address.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ipaddr_checker)]
|
||||
///
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv4(), true);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv4(),
|
||||
/// false);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "ipaddr_checker", issue = "36949")]
|
||||
pub fn is_ipv4(&self) -> bool {
|
||||
match *self {
|
||||
@ -141,6 +215,20 @@ impl IpAddr {
|
||||
}
|
||||
|
||||
/// Returns true if this address is a valid IPv6 address, false if it's a valid IPv4 address.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(ipaddr_checker)]
|
||||
///
|
||||
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert_eq!(IpAddr::V4(Ipv4Addr::new(203, 0, 113, 6)).is_ipv6(), false);
|
||||
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0xdb8, 0, 0, 0, 0, 0, 0)).is_ipv6(),
|
||||
/// true);
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "ipaddr_checker", issue = "36949")]
|
||||
pub fn is_ipv6(&self) -> bool {
|
||||
match *self {
|
||||
|
Loading…
Reference in New Issue
Block a user