Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Dns

Resolves an explicit host through bounded blocking dispatch into owned addresses. Copies the host synchronously before returning; no borrowed host view survives admission. May allocate copied host, task frames and result vector. Native resolver may use hosts/configuration as well as DNS, retaining ordering/duplicates. Cancellation cannot interrupt an already-running platform call; completion waits for that call before discarding results and releasing storage. No unsafe is needed.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.net

import std.net;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str, Family: AddressFamily?, Token: CancellationToken) -> Task<Result<Vector<Address>, NetworkError>>

Resolves an explicit host through bounded blocking dispatch into owned addresses. Copies the host synchronously before returning; no borrowed host view survives admission. May allocate copied host, task frames and result vector. Native resolver may use hosts/configuration as well as DNS, retaining ordering/duplicates. Cancellation cannot interrupt an already-running platform call; completion waits for that call before discarding results and releasing storage. No unsafe is needed. Host: Nonempty printable ASCII, no NUL, at most4096 bytes; borrowed only during creation. Family: Optional IPv4/IPv6 restriction; None admits both without mapped conversion. Token: Owned cancellation observation, inert by default. Return: Unique task yielding owned addresses or typed resolution/admission/cancellation error.

Example

module example.dns_resolution;
from std.collections import Vector;
from std.net import ResolveAddressesAsync, AddressFamily, Address;
from std.task import Task, CancellationSource;
from std.time import Deadline, Instant;
async fn Main() -> Task<i32> {
    let V4Family: AddressFamily? = .Some { Value = .IPv4 };
    let V6Family: AddressFamily? = .Some { Value = .IPv6 };
    var V4 = {
        // Scoped writable carriers end immediately after explicit payload transfer.
        var V4Creation = await ResolveAddressesAsync("127.0.0.1", V4Family);
        switch V4Creation {
            case .Ok { Value = Value: mut Vector<Address>& } => break move(Value);
            case .Err => return 1;
        }
    };
    if V4.IsEmpty || V4[0].Family != .IPv4 || !V4[0].IsLoopback { return 2; }
    var V6 = {
        var V6Creation = await ResolveAddressesAsync("::1", V6Family);
        switch V6Creation {
            case .Ok { Value = Value: mut Vector<Address>& } => break move(Value);
            case .Err => return 3;
        }
    };
    if V6.IsEmpty || V6[0].Family != .IPv6 || !V6[0].IsLoopback { return 4; }
    switch await ResolveAddressesAsync("bad name") {
        case .Err { Error = PatternPayload5128 } => {
            switch PatternPayload5128 {
                case .Failure { Reason = PatternPayload5129 } if (PatternPayload5129 is .InvalidInput) => {}
                default => return 5;
            }
        }
        default => return 5;
    }
    var Stop = {
        var StopCreation = CancellationSource.TryCreate();
        switch StopCreation {
            case .Ok { Value = Value: mut CancellationSource& } => break move(Value);
            case .Err => return 6;
        }
    };
    Stop.RequestCancellation();
    let AnyFamily: AddressFamily? = none;
    switch await ResolveAddressesAsync("127.0.0.1", AnyFamily, Stop.Token) {
        case .Err { Error = PatternPayload5130 } => {
            switch PatternPayload5130 {
                case .Failure { Reason = PatternPayload5131 } if (PatternPayload5131 is .Cancelled) => {}
                default => return 7;
            }
        }
        default => return 7;
    }
    let Now = switch Instant.TryNow() { case .Ok { Value = Value } => break Value; case .Err => return 8; };
    let Expired: Deadline = .Finite { At = Now };
    switch await ResolveAddressesAsync("127.0.0.1", Expired) {
        case .Err { Error = PatternPayload5132 } => {
            switch PatternPayload5132 {
                case .Failure { Reason = PatternPayload5133 } if (PatternPayload5133 is .TimedOut) => {}
                default => return 9;
            }
        }
        default => return 9;
    }
    return 0;
}

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str) -> Task<Result<Vector<Address>, NetworkError>>

Supplies the omitted arguments to ResolveAddressesAsync. Note: Defaults: Family = .None, Token = CancellationToken(). Host: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str, mut Family: AddressFamily?) -> Task<Result<Vector<Address>, NetworkError>>

Supplies the omitted arguments to ResolveAddressesAsync. Note: Defaults: Token = CancellationToken(). Host: Same input, ownership and lifetime contract as the full operation. Family: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str, Limit: Deadline, Family: AddressFamily?, Token: CancellationToken) -> Task<Result<Vector<Address>, NetworkError>>

Copies a host and resolves it against an unchanged absolute deadline. Host: Explicit ASCII bytes borrowed only through synchronous creation. Limit: Finite compatible monotonic boundary or Endless. Family: Optional native IPv4/IPv6 restriction. Token: Owned cancellation observation checked before deadline. Return: Owned result task; timeout waits for already-started native work to quiesce.

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str, mut Limit: Deadline) -> Task<Result<Vector<Address>, NetworkError>>

Supplies the omitted arguments to ResolveAddressesAsync. Note: Defaults: Family = .None, Token = CancellationToken(). Host: Same input, ownership and lifetime contract as the full operation. Limit: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

ResolveAddressesAsync

pub fn ResolveAddressesAsync(Host: str, mut Limit: Deadline, mut Family: AddressFamily?) -> Task<Result<Vector<Address>, NetworkError>>

Supplies the omitted arguments to ResolveAddressesAsync. Note: Defaults: Token = CancellationToken(). Host: Same input, ownership and lifetime contract as the full operation. Limit: Same input, ownership and lifetime contract as the full operation. Family: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library