Struct std::net::SocketAddrV4
1.0.0 · source · pub struct SocketAddrV4 { /* private fields */ }
Expand description
IPv4 套接字地址。
IPv4 套接字地址由 IPv4
地址 和一个 16 位端口号组成,如 IETF RFC 793 中所述。
有关同时包含 IPv4 和 IPv6 套接字地址的类型,请参见 SocketAddr
。
SocketAddrV4
结构体的大小可能会因目标操作系统而异。
不要假设此类型与底层系统表示具有相同的内存布局。
Examples
use std::net::{Ipv4Addr, SocketAddrV4};
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!("127.0.0.1:8080".parse(), Ok(socket));
assert_eq!(socket.ip(), &Ipv4Addr::new(127, 0, 0, 1));
assert_eq!(socket.port(), 8080);
RunImplementations§
source§impl SocketAddrV4
impl SocketAddrV4
sourcepub fn parse_ascii(b: &[u8]) -> Result<SocketAddrV4, AddrParseError>
🔬This is a nightly-only experimental API. (addr_parse_ascii
#101035)
pub fn parse_ascii(b: &[u8]) -> Result<SocketAddrV4, AddrParseError>
addr_parse_ascii
#101035)从字节片中解析 IPv4 套接字地址。
#![feature(addr_parse_ascii)]
use std::net::{Ipv4Addr, SocketAddrV4};
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
assert_eq!(SocketAddrV4::parse_ascii(b"127.0.0.1:8080"), Ok(socket));
Runsource§impl SocketAddrV4
impl SocketAddrV4
const: 1.69.0 · sourcepub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4
pub const fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4
从 IPv4
address 和端口号创建一个新的套接字地址。
Examples
use std::net::{SocketAddrV4, Ipv4Addr};
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
RunTrait Implementations§
source§impl Clone for SocketAddrV4
impl Clone for SocketAddrV4
source§fn clone(&self) -> SocketAddrV4
fn clone(&self) -> SocketAddrV4
返回值的副本。 Read more
source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
从
source
执行复制分配。 Read moresource§impl Debug for SocketAddrV4
impl Debug for SocketAddrV4
source§impl Display for SocketAddrV4
impl Display for SocketAddrV4
1.16.0 · source§impl From<SocketAddrV4> for SocketAddr
impl From<SocketAddrV4> for SocketAddr
source§fn from(sock4: SocketAddrV4) -> SocketAddr
fn from(sock4: SocketAddrV4) -> SocketAddr
将 SocketAddrV4
转换为 SocketAddr::V4
。
1.5.0 · source§impl FromStr for SocketAddrV4
impl FromStr for SocketAddrV4
§type Err = AddrParseError
type Err = AddrParseError
可以从解析中返回的相关错误。
source§fn from_str(s: &str) -> Result<SocketAddrV4, AddrParseError>
fn from_str(s: &str) -> Result<SocketAddrV4, AddrParseError>
解析字符串
s
以返回此类型的值。 Read moresource§impl Hash for SocketAddrV4
impl Hash for SocketAddrV4
1.45.0 · source§impl Ord for SocketAddrV4
impl Ord for SocketAddrV4
source§impl PartialEq<SocketAddrV4> for SocketAddrV4
impl PartialEq<SocketAddrV4> for SocketAddrV4
1.45.0 · source§impl PartialOrd<SocketAddrV4> for SocketAddrV4
impl PartialOrd<SocketAddrV4> for SocketAddrV4
source§fn partial_cmp(&self, other: &SocketAddrV4) -> Option<Ordering>
fn partial_cmp(&self, other: &SocketAddrV4) -> Option<Ordering>
source§impl ToSocketAddrs for SocketAddrV4
impl ToSocketAddrs for SocketAddrV4
§type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
在此类型可能对应的套接字地址上返回的迭代器。
source§fn to_socket_addrs(&self) -> Result<IntoIter<SocketAddr>>
fn to_socket_addrs(&self) -> Result<IntoIter<SocketAddr>>
将此对象转换为已解析的
SocketAddr
的迭代器。 Read moreimpl Copy for SocketAddrV4
impl Eq for SocketAddrV4
impl StructuralEq for SocketAddrV4
impl StructuralPartialEq for SocketAddrV4
Auto Trait Implementations§
impl RefUnwindSafe for SocketAddrV4
impl Send for SocketAddrV4
impl Sync for SocketAddrV4
impl Unpin for SocketAddrV4
impl UnwindSafe for SocketAddrV4
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more