net::addr
Addresses: IP addresses, the address-plus-port pair every socket constructor takes, and a URL parser.
public module net::addr::ip;
public module net::addr::socket_addr;
public module net::addr::sockaddr;
public module net::addr::url;
| File | What it holds | Import |
|---|---|---|
ip | IpV4Addr, IpV6Addr, IpAddr | import std::net::addr::ip; |
socket_addr | SocketAddr | import std::net::addr::socket_addr; |
url | Url, UrlError | import std::net::addr::url; |
net::addr::sockaddr holds pack_sockaddr_in and unpack_sockaddr, the hand-packed struct sockaddr bridge every socket call goes through. It is public for code that needs to speak to a raw socket API, and otherwise not something you call; it has no page.
IPv6 addressing is parsed and represented, and TCP opens an
AF_INET6socket for a v6 address. UDP is IPv4-only for now:bind,connect, andUdpSendToreject anIpAddr::V6up front withUnsupported.
public function name() { ... }
public:Visible to any module that imports this one - the default for top-level items and for struct fields, so it is mostly written to be explicit. public: opens a visibility block that groups the members after it.
public module collections::array;In a directory's _module.cryo aggregator, lists a submodule and whether it is public. Importing the directory's namespace sees only the modules declared public here.
namespace std::net::addr::sockaddr;sockaddr_in packing/unpacking + socket-option helpers.
type struct IpV4Addr {
a: u8;
b: u8;
c: u8;
d: u8;
}type struct IpV6Addr {
segments: [u8;
16];
}Sixteen octets in network byte order. parse accepts the canonical text forms (full 8-group, ::-compressed, and trailing embedded-v4); addresses may also be constructed directly.
type enum IpAddr {
V4(IpV4Addr);
V6(IpV6Addr);
}import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
type struct Url {
scheme: Str;
host: Str;
port: u16;
path: Str;
query: Option<Str>;
fragment: Option<Str>;
}net::addr::url: a parser for absolute URLs.
std::net::addr::urltype enum UrlError {
MissingScheme;
EmptyScheme;
EmptyHost;
InvalidPort;
}Why a URL failed to parse.
std::net::addr::urltype struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
AddressFamily::AF_INET6 = 10type struct UdpSendTo {
socket: UdpSocket;
buf: Array<u8>;
dest: SocketAddr;
rt: Reactor*;
}Send one datagram to dest. Completes with the number of bytes the kernel accepted; a partial datagram is never sent, so that is the whole buffer on success. The buffer comes back untouched.
IpAddr::V6(IpV6Addr)IoErrorKind::UnsupportedThe operation is recognized but not implemented on this build (e.g. a feature stubbed pending implementation, or a platform the stdlib doesn't support yet). Distinct from InvalidInput (caller's fault) and Other (unmapped errno).