Address
Owns an immutable numeric IPv4 or IPv6 address without allocation. Copies own independent fixed-size bytes. Numeric construction performs no I/O, lookup or parsing. IPv4 scope is zero; IPv6 scope zero is unspecified. A nonzero scope is an explicit interface identifier interpreted by the selected adapter. Public operations never rewrite IPv4-mapped IPv6 or discard scope. Concurrent readonly access is safe while the value remains alive and is not moved/replaced. Borrowed Bytes views expire on replacement, movement or destruction.
Module std.net
import std.net;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
Address
pub struct AddressOwns an immutable numeric IPv4 or IPv6 address without allocation. Copies own independent fixed-size bytes. Numeric construction performs no I/O, lookup or parsing. IPv4 scope is zero; IPv6 scope zero is unspecified. A nonzero scope is an explicit interface identifier interpreted by the selected adapter. Public operations never rewrite IPv4-mapped IPv6 or discard scope. Concurrent readonly access is safe while the value remains alive and is not moved/replaced. Borrowed Bytes views expire on replacement, movement or destruction.
Example
module example.network_address;
from std.net import Address, AddressFamily, Endpoint;
fn Main() -> i32 {
let Any = default(Address);
if Any.Family != .IPv4 || !Any.IsUnspecified || Any.IsLoopback || Any.ScopeId != 0 { return 1; }
let Loopback = Address.CreateIPv4(127_byte, 0_byte, 0_byte, 1_byte);
if !Loopback.IsLoopback || Loopback.IsUnspecified || Loopback.Bytes().Length != 4 { return 2; }
if Loopback.Bytes()[0] != 127_byte || !Loopback.Equals(Address.CreateIPv4(127_byte, 0_byte, 0_byte, 1_byte)) { return 3; }
var Units: byte[16] = default(byte[16]);
Units[15] = 1_byte;
let Wide = Address.CreateIPv6(Units);
Units[15] = 2_byte;
if Wide.Family != .IPv6 || !Wide.IsLoopback || Wide.Bytes().Length != 16 || Wide.Bytes()[15] != 1_byte { return 4; }
let Scoped = Address.CreateIPv6(default(byte[16]), 7_u32);
if !Scoped.IsUnspecified || Scoped.ScopeId != 7 || Scoped.Equals(Address.CreateIPv6(default(byte[16]))) { return 5; }
let Target = Endpoint.Create(Loopback, 8080_u16);
if Target.Port != 8080 || !Target.Address.Equals(Loopback) { return 6; }
let Default = default(Endpoint);
if Default.Port != 0 || !Default.Address.IsUnspecified { return 7; }
return 0;
}Address.CreateIPv4
pub static fn CreateIPv4(First: byte, Second: byte, Third: byte, Fourth: byte) -> AddressCreates an IPv4 address from network-order octets. First: Most significant address octet. Second: Second octet. Third: Third octet. Fourth: Least significant octet. Return: Independent owned address; no allocation or native effect.
Address.CreateIPv6
pub static fn CreateIPv6(mut Units: byte[16], ScopeId: u32) -> AddressCopies sixteen network-order octets and an explicit interface scope. Units: Exact numeric address bytes, copied into independent storage. ScopeId: Explicit IPv6 scope; zero means unspecified, default zero. Return: Owned IPv6 value without lookup, normalization or allocation.
Address.CreateIPv6
pub static fn CreateIPv6(mut Units: byte[16]) -> AddressSupplies the omitted arguments to CreateIPv6. Note: Defaults: ScopeId = 0. Units: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's address value.
Address.Family
pub Family: AddressFamily;Observes the exact numeric family. Return: IPv4 or IPv6.
Address.ScopeId
pub ScopeId: u32;Observes explicit IPv6 scope, or zero for IPv4. Return: Interface identifier without host validation or lookup.
Address.Bytes
pub readonly fn Bytes() -> readonly byte[]Borrows active network-order octets without allocation. Return: Four or sixteen readonly bytes; valid until owner replacement, movement or destruction. The view does not retain this Address.
Address.IsUnspecified
pub IsUnspecified: bool;Tests the all-zero numeric address in either family. Scope does not change numeric classification. No reachability is promised. Return: True only when every active octet is zero; constant bounded work.
Address.IsLoopback
pub IsLoopback: bool;Tests IPv4 127/8 or IPv6 ::1, without mapped-family conversion. Return: Numeric loopback classification; no I/O or host policy lookup.
Address.Equals
pub readonly fn Equals(Other: readonly Address&) -> boolCompares exact family, active bytes and scope with bounded work. Other: Borrowed numeric value required only through return. Return: True for identical numeric representation, including scope.