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]

Construct new from IpAddr and port.

Methods from Deref<Target = SocketAddr>

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)));

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);

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);
}

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]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for SocketAddr
[src]

Formats the value using the given formatter.

impl Hash for SocketAddr
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl Eq for SocketAddr
[src]

impl PartialEq for SocketAddr
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Deref for SocketAddr
[src]

The resulting type after dereferencing

The method called to dereference a value

impl Display for SocketAddr
[src]

Formats the value using the given formatter. Read more

impl Encodable for SocketAddr
[src]

Serialize a value using an Encoder.

impl Decodable for SocketAddr
[src]

Deserialize a value using a Decoder.