本文簡要介紹rust語言中 Enum std::net::IpAddr
的用法。
用法
pub enum IpAddr {
V4(Ipv4Addr),
V6(Ipv6Addr),
}
IP 地址,IPv4 或 IPv6。
此枚舉可以包含 Ipv4Addr
或 Ipv6Addr
,有關更多詳細信息,請參閱它們各自的文檔。
IpAddr
實例的大小可能因目標操作係統而異。
例子
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);
變體
V4(Ipv4Addr)
元組字段
0: Ipv4Addr
IPv4 地址。
V6(Ipv6Addr)
元組字段
0: Ipv6Addr
IPv6 地址。
相關用法
- Rust IpAddr.is_multicast用法及代碼示例
- Rust IpAddr.is_loopback用法及代碼示例
- Rust IpAddr.is_global用法及代碼示例
- Rust IpAddr.to_canonical用法及代碼示例
- Rust IpAddr.is_ipv6用法及代碼示例
- Rust IpAddr.is_ipv4用法及代碼示例
- Rust IpAddr.is_unspecified用法及代碼示例
- Rust IpAddr.is_documentation用法及代碼示例
- Rust IpAddr.is_benchmarking用法及代碼示例
- Rust Ipv4Addr.is_global用法及代碼示例
- Rust Ipv6Addr.is_multicast用法及代碼示例
- Rust Ipv4Addr.new用法及代碼示例
- Rust Ipv6Addr.is_documentation用法及代碼示例
- Rust Ipv6Addr.is_unspecified用法及代碼示例
- Rust Ipv6Addr.octets用法及代碼示例
- Rust Ipv6Addr.multicast_scope用法及代碼示例
- Rust Ipv4Addr.is_link_local用法及代碼示例
- Rust Ipv6Addr.is_unicast_link_local用法及代碼示例
- Rust Ipv6Addr.to_ipv4用法及代碼示例
- Rust Ipv4Addr.is_loopback用法及代碼示例
- Rust Ipv6Addr.to_canonical用法及代碼示例
- Rust Ipv6Addr.is_unique_local用法及代碼示例
- Rust Ipv6Addr.is_benchmarking用法及代碼示例
- Rust Ipv4Addr.is_private用法及代碼示例
- Rust Ipv6Addr.is_loopback用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 Enum std::net::IpAddr。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。