Struct std::net::SocketAddrV4
1.0.0 · source · [−]pub struct SocketAddrV4 { /* private fields */ }
Expand description
An IPv4 socket address.
IPv4 socket addresses consist of an IPv4
address and a 16-bit port number, as
stated in IETF RFC 793.
See SocketAddr
for a type encompassing both IPv4 and IPv6 socket addresses.
The size of a SocketAddrV4
struct may vary depending on the target operating
system. Do not assume that this type has the same memory layout as the underlying
system representation.
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
Creates a new socket address from an IPv4
address and a port number.
Examples
use std::net::{SocketAddrV4, Ipv4Addr};
let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080);
RunTrait Implementations
Converts a SocketAddrV4
into a SocketAddr::V4
.
type Err = AddrParseError
type Err = AddrParseError
The associated error which can be returned from parsing.
Parses a string s
to return a value of this type. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
Converts this object to an iterator of resolved SocketAddr
s. Read more