Enum std::net::IpAddr 1.7.0[−][src]
Expand description
IP 地址,IPv4 或 IPv6。
该枚举可以包含 Ipv4Addr 或 Ipv6Addr,有关更多详细信息,请参见其各自的文档。
IpAddr 实例的大小可能会因目标操作系统而异。
Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
assert_eq!("127.0.0.1".parse(), Ok(localhost_v4));
assert_eq!("::1".parse(), Ok(localhost_v6));
assert_eq!(localhost_v4.is_ipv6(), false);
assert_eq!(localhost_v4.is_ipv4(), true);RunVariants
V4(Ipv4Addr)
Tuple Fields
0: Ipv4AddrIPv4 地址。
V6(Ipv6Addr)
Tuple Fields
0: Ipv6AddrIPv6 地址。
Implementations
返回 true 作为特殊的 ‘unspecified’ 地址。
有关更多详细信息,请参见 Ipv4Addr::is_unspecified() 和 Ipv6Addr::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);Run如果这是一个回环地址,则返回 true。
有关更多详细信息,请参见 Ipv4Addr::is_loopback() 和 Ipv6Addr::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);Run如果该地址似乎是可全局路由的,则返回 true。
有关更多详细信息,请参见 Ipv4Addr::is_global() 和 Ipv6Addr::is_global() 的文档。
Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
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);Run如果这是一个多播地址,则返回 true。
有关更多详细信息,请参见 Ipv4Addr::is_multicast() 和 Ipv6Addr::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);Run如果此地址在文档指定的范围内,则返回 true。
有关更多详细信息,请参见 Ipv4Addr::is_documentation() 和 Ipv6Addr::is_documentation() 的文档。
Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
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
);Run如果此地址在为基准测试指定的范围内,则返回 true。
有关更多详细信息,请参见 Ipv4Addr::is_benchmarking() 和 Ipv6Addr::is_benchmarking() 的文档。
Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(198, 19, 255, 255)).is_benchmarking(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);Run如果此地址是 IPv4 address,则返回 true,否则返回 false。
Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
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);Run如果此地址是 IPv6 address,则返回 true,否则返回 false。
Examples
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
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);Run如果它是 IPv4 映射的 IPv6 地址,则将此地址转换为 IpAddr::V4,否则按原样返回 self。
Examples
#![feature(ip)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
assert_eq!(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)).to_canonical().is_loopback(), true);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).is_loopback(), false);
assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);RunTrait Implementations
从 16 个元素的字节数组创建 IpAddr::V6。
Examples
use std::net::{IpAddr, Ipv6Addr};
let addr = IpAddr::from([
25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8,
17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8,
]);
assert_eq!(
IpAddr::V6(Ipv6Addr::new(
0x1918, 0x1716,
0x1514, 0x1312,
0x1110, 0x0f0e,
0x0d0c, 0x0b0a
)),
addr
);Runtype Err = AddrParseError
type Err = AddrParseError
可以从解析中返回的相关错误。
如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more
如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more
如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more
如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more
如果存在,则此方法返回 self 和 other 值之间的顺序。 Read more