Struct socket_addr::SocketAddr
[−]
[src]
pub struct SocketAddr(pub SocketAddr);
Wrapper around std::net::SocketAddr
to enable it to be encoded and decoded.
Methods
impl SocketAddr
[src]
Methods from Deref<Target = SocketAddr>
fn ip(&self) -> IpAddr
1.7.0
Returns the IP address associated with this socket address.
Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
fn port(&self) -> u16
1.0.0
Returns the port number associated with this socket address.
Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); assert_eq!(socket.port(), 8080);
fn is_ipv4(&self) -> bool
1.16.0
Returns true
if the IP address in this SocketAddr
is an
IPv4 address, and false
otherwise.
Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; fn main() { let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080); assert_eq!(socket.is_ipv4(), true); assert_eq!(socket.is_ipv6(), false); }
fn is_ipv6(&self) -> bool
1.16.0
Returns true
if the IP address in this SocketAddr
is an
IPv6 address, and false
otherwise.
Examples
use std::net::{IpAddr, Ipv6Addr, SocketAddr}; fn main() { let socket = SocketAddr::new( IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080); assert_eq!(socket.is_ipv4(), false); assert_eq!(socket.is_ipv6(), true); }
Trait Implementations
impl Copy for SocketAddr
[src]
impl Clone for SocketAddr
[src]
fn clone(&self) -> SocketAddr
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for SocketAddr
[src]
impl Hash for SocketAddr
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Eq for SocketAddr
[src]
impl PartialEq for SocketAddr
[src]
fn eq(&self, __arg_0: &SocketAddr) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &SocketAddr) -> bool
This method tests for !=
.
impl Deref for SocketAddr
[src]
type Target = SocketAddr
The resulting type after dereferencing
fn deref(&self) -> &SocketAddr
The method called to dereference a value
impl Display for SocketAddr
[src]
impl Encodable for SocketAddr
[src]
impl Decodable for SocketAddr
[src]
fn decode<D: Decoder>(d: &mut D) -> Result<SocketAddr, D::Error>
Deserialize a value using a Decoder
.