Skip to content
CryoCryo home
Stdlibnet::addr

socket_addr

import std::net::addr::socket_addr; · source

SocketAddr

type struct SocketAddr {
    ip:   IpAddr;
    port: u16;

    static new(ip: IpAddr, port: u16) -> SocketAddr;
    static any_v4(port: u16) -> SocketAddr;
    static localhost_v4(port: u16) -> SocketAddr;
    static any_v6(port: u16) -> SocketAddr;
    static localhost_v6(port: u16) -> SocketAddr;
    static parse_v4(source: Str) -> Option<SocketAddr>;
}

An IP address paired with a port. This is what every socket constructor takes — TcpListener::bind, TcpConnect::start, UdpSocket::bind — and what local_addr() hands back.

any_v4(port) is 0.0.0.0:port, binding on every IPv4 interface; localhost_v4(port) is 127.0.0.1:port; the _v6 pair are [::] and [::1]. parse_v4 reads a.b.c.d:port, returning None if the address or port is malformed or the port is out of range.

import std::net::addr::socket_addr;

const addr: SocketAddr = SocketAddr::any_v4(8080);

POD — copied by value, nothing to drop.