dns
import std::net::dns; · source
Types
ResolvedAddrs
type struct ResolvedAddrs {
addrs: Array<IpAddr>;
length(&this) -> u64;
get(&this, index: u64) -> Option<IpAddr>;
first_ipv4(&this, port: u16) -> Option<SocketAddr>;
}
Every address the resolver returned, in its order. first_ipv4(port) is the common case — the first v4 address paired with a port, ready to dial — and it must be dropped.
Properties
| Property | Type |
|---|---|
addrs | Array<IpAddr> |
Methods
length(&this) -> u64;
length(&this) -> u64;Number of resolved addresses (>= 1 on a successful resolve).
get(&this, index: u64) -> Option<IpAddr>;
get(&this, index: u64) -> Option<IpAddr>;The i-th resolved address, or None if out of range.
first_ipv4(&this, port: u16) -> Option<SocketAddr>;
first_ipv4(&this, port: u16) -> Option<SocketAddr>;The first IPv4 address in the result, paired with port, or None if the name resolved only to AAAA records. Callers that can dial a v6 address should walk get instead; this exists for the layers that cannot yet.
Resolve
type struct Resolve {
host: Str;
job: ResolveJob*;
static start(host: Str) -> Resolve;
}
The async spelling of resolve: it runs the same getaddrinfo call on the executor's blocking pool and wakes the task when it finishes, which is what HttpsClient uses. Dropping it mid-resolution releases the future's side of the job; the pool frees the block when the call eventually returns.
Properties
| Property | Type |
|---|---|
host | Str |
job | ResolveJob* |
Constructors
static start(host: Str) -> Resolve;
static start(host: Str) -> Resolve;Begin resolving host. Nothing is submitted until the first poll, so a Resolve that is never awaited costs nothing.
Trait implementations
implement trait Future for struct Resolve
implement trait Drop for struct Resolve
Free Functions
Name resolution
| Function / future | Returns |
|---|---|
resolve(host) | Result<ResolvedAddrs, IoError> — blocking. |
resolve_one(host) | The first address. |
lookup(host, port) | Every address paired with port. |
Resolve::start(host) | ResolvedAddrs, without blocking the executor. |
Resolution goes through getaddrinfo, with its error codes mapped into IoError. getaddrinfo has no non-blocking form on any platform, so the three functions block the calling thread.
function resolve(host: Str) -> Result<ResolvedAddrs, IoError>;
function resolve(host: Str) -> Result<ResolvedAddrs, IoError>;Resolve host to every A / AAAA record the resolver returns, in the order it returns them (already preference-sorted by glibc's RFC 3484 rules). host may be a name or a numeric literal - a numeric address resolves to itself. Fails with NotFound for an unknown name, WouldBlock for a temporary resolver failure.
function resolve_one(host: Str) -> Result<IpAddr, IoError>;
function resolve_one(host: Str) -> Result<IpAddr, IoError>;Resolve host to a single address - the first (most-preferred) record. The common case for "connect to this name".
function lookup(host: Str, port: u16) -> Result<Array<SocketAddr>, IoError>;
function lookup(host: Str, port: u16) -> Result<Array<SocketAddr>, IoError>;Resolve host and pair every address with port, ready to hand to TcpConnect::start / UdpSocket::connect. The returned Array must be dropped by the caller.
Constants
const AF_INET: u32 = 2;
![target(unix)]
const AF_INET6: u32 = 10;
![target(windows)]
const AF_INET6: u32 = 23;type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type 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.
type struct ResolvedAddrs {
addrs: Array<IpAddr>;
}The addresses a hostname resolved to. Owns the backing Array; call drop when done.
ResolvedAddrs.addrs: Array<IpAddr>type struct Array<T, A = GlobalAlloc> where A: Allocator {
ptr: T*;
length: i64;
capacity: i64;
alloc: A;
}Array<T, A>: growable, heap-backed, contiguous sequence.
std::collections::arraytype enum IpAddr {
V4(IpV4Addr);
V6(IpV6Addr);
}ResolvedAddrs::length(&this) -> u64Number of resolved addresses (>= 1 on a successful resolve).
&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
ResolvedAddrs::get(&this, index: u64) -> Option<IpAddr>The i-th resolved address, or None if out of range.
(parameter) index: u64ResolvedAddrs::first_ipv4(&this, port: u16) -> Option<SocketAddr>The first IPv4 address in the result, paired with port, or None if the name resolved only to AAAA records. Callers that can dial a v6 address should walk get instead; this exists for the layers that cannot yet.
(parameter) port: u16type struct Resolve {
host: Str;
job: ResolveJob*;
}Resolve host without stalling the executor: the lookup runs on the BlockingPool's threads and the task parks until it answers.
Resolve.host: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::strResolve.job: ResolveJob*type struct ResolveJob {
job: BlockingJob;
host: String;
addrs: ResolvedAddrs;
err: IoError;
produced: boolean;
ok: boolean;
}The block a Resolve hands to the blocking pool: the pool's job header, the request, and the slot the answer lands in.
static name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static Resolve::start(host: Str) -> ResolveBegin resolving host. Nothing is submitted until the first poll, so a Resolve that is never awaited costs nothing.
(parameter) host: Strtype struct Resolve {
host: Str;
job: ResolveJob*;
}Resolve host without stalling the executor: the lookup runs on the BlockingPool's threads and the task parks until it answers.
const NAME: Type = value;At module level, a true compile-time constant, conventionally SCREAMING_SNAKE_CASE. (mut at module level declares mutable global state instead.)
const AF_INET: u32 = 2;const AF_INET6: u32 = 10;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).
ResolvedAddrs::first_ipv4(&this, port: u16) -> Option<SocketAddr>The first IPv4 address in the result, paired with port, or None if the name resolved only to AAAA records. Callers that can dial a v6 address should walk get instead; this exists for the layers that cannot yet.
ResolvedAddrs.addrs: Array<IpAddr>ResolvedAddrs::length(&this) -> u64Number of resolved addresses (>= 1 on a successful resolve).
function resolve(host: Str) -> Result<ResolvedAddrs, IoError>Resolve host to every A / AAAA record the resolver returns, in the order it returns them (already preference-sorted by glibc's RFC 3484 rules). host may be a name or a numeric literal - a numeric address resolves to itself. Fails with NotFound for an unknown name, WouldBlock for a temporary resolver failure.
ResolvedAddrs::get(&this, index: u64) -> Option<IpAddr>The i-th resolved address, or None if out of range.
AlpnProtocol::Nonetype struct HttpsClient {
connector: TlsConnector;
}ResolveJob.host: StringResolveJob.job: BlockingJobstatic Resolve::start(host: Str) -> ResolveBegin resolving host. Nothing is submitted until the first poll, so a Resolve that is never awaited costs nothing.
implement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referencetype trait Future {
type Output;
poll(mut &this, cx: Context*) -> Poll<This::Output>;
}An asynchronous computation. poll drives it one step: Ready(v) when the value is available, Pending when it is not yet (the future has arranged, via cx's waker, to be polled again later).
implement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language referencetype struct ResolvedAddrs {
addrs: Array<IpAddr>;
}The addresses a hostname resolved to. Owns the backing Array; call drop when done.
type struct IoError {
kind: IoErrorKind;
os_code: i32;
}function resolve_one(host: Str) -> Result<IpAddr, IoError>Resolve host to a single address - the first (most-preferred) record. The common case for "connect to this name".
function lookup(host: Str, port: u16) -> Result<Array<SocketAddr>, IoError>Resolve host and pair every address with port, ready to hand to TcpConnect::start / UdpSocket::connect. The returned Array must be dropped by the caller.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
function resolve(host: Str) -> Result<ResolvedAddrs, IoError>Resolve host to every A / AAAA record the resolver returns, in the order it returns them (already preference-sorted by glibc's RFC 3484 rules). host may be a name or a numeric literal - a numeric address resolves to itself. Fails with NotFound for an unknown name, WouldBlock for a temporary resolver failure.
IoErrorKind::NotFoundIoErrorKind::WouldBlockfunction resolve_one(host: Str) -> Result<IpAddr, IoError>Resolve host to a single address - the first (most-preferred) record. The common case for "connect to this name".
function lookup(host: Str, port: u16) -> Result<Array<SocketAddr>, IoError>Resolve host and pair every address with port, ready to hand to TcpConnect::start / UdpSocket::connect. The returned Array must be dropped by the caller.
type struct TcpConnect {
fd: i32;
addr: [u8;
28];
addrlen: u32;
err: IoError;
rt: Reactor*;
}Connect to a remote address without blocking. The socket is opened and the handshake started when the future is created; each poll asks the OS whether it finished, parking on writability in between. The socket is closed if the future is dropped before it completes.
std::net::socket::tcpstatic TcpConnect::start(remote: SocketAddr) -> TcpConnectOpen a non-blocking socket and start connecting to remote.
type struct UdpSocket {
fd: i32;
}UdpSocket::connect(mut &this, remote: SocketAddr) -> Result<(), IoError>Pin a default peer. After this, UdpSend/UdpRecv talk to remote and the kernel filters incoming datagrams to that source. Does not exchange packets - UDP connect is local bookkeeping only, so it cannot block and stays a plain call.