Silk

silk/network_address

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.

Owned network addresses, endpoints, and validated origin hosts.

When to use

Parse URI hosts before resolution, retain the resulting Host for HTTP/TLS identity, and pass its numeric address or domain to silk.resolver.

Details

IPv4 and IPv6 own network-order octets. DomainHost owns its admitted source spelling in fixed 253-byte storage and compares ASCII case-insensitively. Parsing and formatting allocate nothing.

Gotchas

This profile accepts prepared ASCII LDH/A-label domains only. It rejects search-root dots, Unicode mapping, escapes, zones, IPvFuture, userinfo, ports, and legacy libc IPv4 spellings.

Import as NetworkAddress with import silk.network_address { NetworkAddress }.

Public declarations: 12.

AddressReason

pub enum AddressReason

The failed network-address admission rule.

Empty

Empty = 0

The numeric address input is empty.

InvalidCharacter

InvalidCharacter = 1

An input byte is not admitted in this position.

InvalidComponent

InvalidComponent = 2

An address component has invalid syntax.

LeadingZero

LeadingZero = 3

An IPv4 component contains a prohibited leading zero.

ComponentOverflow

ComponentOverflow = 4

An address component exceeds its numeric range.

WrongComponentCount

WrongComponentCount = 5

The address has the wrong number of components.

MultipleCompression

MultipleCompression = 6

The IPv6 spelling contains multiple compression markers.

CompressionWithoutOmission

CompressionWithoutOmission = 7

IPv6 compression does not omit any component.

HostReason

pub enum HostReason

The failed domain-host admission rule.

EmptyName

EmptyName = 0

The domain name is empty.

NameTooLong

NameTooLong = 1

The domain name exceeds the admitted byte length.

EmptyLabel

EmptyLabel = 2

A domain label is empty.

LabelTooLong

LabelTooLong = 3

A domain label exceeds the admitted byte length.

Nul

Nul = 4

The domain contains a NUL byte.

NonAscii

NonAscii = 5

The domain contains a non-ASCII byte.

InvalidCharacter

InvalidCharacter = 6

An input byte is not admitted in this position.

EdgeHyphen

EdgeHyphen = 7

A domain label begins or ends with a hyphen.

InvalidALabel

InvalidALabel = 8

An encoded internationalized label is invalid.

TrailingDot

TrailingDot = 9

The domain has a prohibited trailing dot.

NumericFinalLabel

NumericFinalLabel = 10

The final domain label is entirely numeric.

UnsupportedHostForm

pub enum UnsupportedHostForm

A URI host form outside the first network profile.

IpvFuture

IpvFuture = 0

The host uses unsupported IPvFuture syntax.

ZoneIdentifier

ZoneIdentifier = 1

The host contains an unsupported IPv6 zone identifier.

EscapedHost

EscapedHost = 2

The host contains unsupported percent escapes.

UserInfo

UserInfo = 3

The host input contains URI user information.

PortDelimiter

PortDelimiter = 4

The host input contains a port delimiter.

UriDelimiter

UriDelimiter = 5

The host input contains a URI delimiter.

AddressError

pub union AddressError

A typed value-construction or presentation failure.

InvalidAddress

AddressError.InvalidAddress { reason: AddressReason, offset: usize }: AddressError

Numeric address admission failed.

Field reason

pub reason: AddressReason

The admission rule that rejected the supplied bytes.

Field offset

pub offset: usize

The zero-based byte offset of the rejected input.

InvalidHost

AddressError.InvalidHost { reason: HostReason, offset: usize }: AddressError

Domain host admission failed.

Field reason

pub reason: HostReason

The admission rule that rejected the supplied bytes.

Field offset

pub offset: usize

The zero-based byte offset of the rejected input.

InvalidPort

AddressError.InvalidPort { value: usize }: AddressError

The supplied port is outside 0..65535.

Field value

pub value: usize

The supplied port number outside the admitted 0..65535 range.

UnsupportedForm

AddressError.UnsupportedForm { form: UnsupportedHostForm, offset: usize }: AddressError

The input uses an unsupported host form.

Field form

pub form: UnsupportedHostForm

The unsupported URI host form.

Field offset

pub offset: usize

The zero-based byte offset of the rejected input.

OutputTooSmall

AddressError.OutputTooSmall { required: usize, available: usize }: AddressError

The supplied output cannot hold the complete formatted value.

Field required

pub required: usize

The output capacity needed for the complete spelling.

Field available

pub available: usize

The output capacity supplied by the caller.

Ipv4Address

pub struct Ipv4Address

Four owned network-order IPv4 octets.

Associated function Ipv4Address.fromOctets

pub fn fromOctets(octets: Array<u8, 4>) -> Ipv4Address

Constructs an IPv4 address from exact network-order octets.

Associated function Ipv4Address.parse

pub fn parse<'life0>(bytes: &'life0 [u8]) -> silk/result.Result<silk/network_address.Ipv4Address, silk/network_address.AddressError>

Parses a strict RFC 3986 decimal dotted quad.

Method Ipv4Address.octets

pub fn octets<'life0>(self: &'life0 Ipv4Address) -> Array<u8, 4>

Returns the owned network-order octets by value.

Method Ipv4Address.equals

pub fn equals<'life0, 'life1>(self: &'life0 Ipv4Address, other: &'life1 Ipv4Address) -> bool

Reports exact binary equality.

Method Ipv4Address.formatInto

pub fn formatInto<'life0, 'life1>(self: &'life0 Ipv4Address, output: &'life1 mut [u8]) -> silk/result.Result<usize, silk/network_address.AddressError>

Formats canonical decimal dotted-quad text without partial output.

Ipv6Address

pub struct Ipv6Address

Sixteen owned network-order IPv6 octets.

Associated function Ipv6Address.fromOctets

pub fn fromOctets(octets: Array<u8, 16>) -> Ipv6Address

Constructs an IPv6 address from exact network-order octets.

Associated function Ipv6Address.parse

pub fn parse<'life0>(bytes: &'life0 [u8]) -> silk/result.Result<silk/network_address.Ipv6Address, silk/network_address.AddressError>

Parses RFC 4291 IPv6 text without zones or IPvFuture.

Method Ipv6Address.octets

pub fn octets<'life0>(self: &'life0 Ipv6Address) -> Array<u8, 16>

Returns the owned network-order octets by value.

Method Ipv6Address.equals

pub fn equals<'life0, 'life1>(self: &'life0 Ipv6Address, other: &'life1 Ipv6Address) -> bool

Reports exact binary equality.

Method Ipv6Address.formatInto

pub fn formatInto<'life0, 'life1>(self: &'life0 Ipv6Address, output: &'life1 mut [u8]) -> silk/result.Result<usize, silk/network_address.AddressError>

Formats canonical RFC 5952 lowercase text without partial output.

IpAddress

pub union IpAddress

An owned numeric network address whose family remains explicit.

V4

IpAddress.V4 { value: Ipv4Address }: IpAddress

An IPv4 address.

Field value

pub value: Ipv4Address

The four network-order IPv4 octets.

V6

IpAddress.V6 { value: Ipv6Address }: IpAddress

An IPv6 address.

Field value

pub value: Ipv6Address

The sixteen network-order IPv6 octets.

Method IpAddress.isV4

pub fn isV4<'life0>(self: &'life0 IpAddress) -> bool

Reports whether this address is IPv4.

Method IpAddress.equals

pub fn equals<'life0, 'life1>(self: &'life0 IpAddress, other: &'life1 IpAddress) -> bool

Reports family-sensitive exact equality.

Method IpAddress.formatInto

pub fn formatInto<'life0, 'life1>(self: &'life0 IpAddress, output: &'life1 mut [u8]) -> silk/result.Result<usize, silk/network_address.AddressError>

Formats the selected canonical address form.

Port

pub struct Port

A checked transport port. Zero is valid for listener binding.

Associated function Port.make

pub fn make(value: usize) -> silk/result.Result<silk/network_address.Port, silk/network_address.AddressError>

Checks a pointer-width integer as an inclusive u16 transport port.

Associated function Port.fromU16

pub fn fromU16(value: u16) -> Port

Constructs a port from an already checked u16.

Method Port.value

pub fn value<'life0>(self: &'life0 Port) -> u16

Returns the underlying checked u16.

Endpoint

pub struct Endpoint

An owned connectable numeric address and port.

Associated function Endpoint.make

pub fn make(address: IpAddress, port: Port) -> Endpoint

Owns one numeric address and checked port.

Method Endpoint.address

pub fn address<'life0>(self: &'life0 Endpoint) -> IpAddress

Returns the owned address by value.

Method Endpoint.port

pub fn port<'life0>(self: &'life0 Endpoint) -> Port

Returns the checked port by value.

Method Endpoint.equals

pub fn equals<'life0, 'life1>(self: &'life0 Endpoint, other: &'life1 Endpoint) -> bool

Reports exact address-and-port equality.

DomainHost

pub struct DomainHost

A validated absolute ASCII domain in preserved source spelling.

Associated function DomainHost.make

pub fn make<'life0>(bytes: &'life0 [u8]) -> silk/result.Result<silk/network_address.DomainHost, silk/network_address.AddressError>

Copies and validates an absolute unrooted ASCII LDH/A-label domain.

Method DomainHost.bytes

pub fn bytes<'a>(self: &'a DomainHost) -> &'a [u8]

Borrows the preserved source-spelling bytes.

Method DomainHost.length

pub fn length<'life0>(self: &'life0 DomainHost) -> usize

Returns the stored byte length.

Method DomainHost.equals

pub fn equals<'life0, 'life1>(self: &'life0 DomainHost, other: &'life1 DomainHost) -> bool

Reports ASCII case-insensitive equality.

Host

pub union Host

A classified owned origin host.

Domain

Host.Domain { value: DomainHost }: Host

A validated ASCII domain host.

Field value

pub value: DomainHost

The validated ASCII domain in its original spelling.

Ipv4

Host.Ipv4 { value: Ipv4Address }: Host

An owned IPv4 origin host.

Field value

pub value: Ipv4Address

The four network-order IPv4 octets.

Ipv6

Host.Ipv6 { value: Ipv6Address }: Host

An owned IPv6 origin host.

Field value

pub value: Ipv6Address

The sixteen network-order IPv6 octets.

Associated function Host.parse

pub fn parse<'life0>(bytes: &'life0 [u8]) -> silk/result.Result<silk/network_address.Host, silk/network_address.AddressError>

Classifies an RFC 3986 URI host into owned numeric or domain identity.

Method Host.numeric

pub fn numeric<'life0>(self: &'life0 Host) -> () | silk/network_address.IpAddress

Returns the numeric address when this host is numeric.

NetworkAddress

pub struct NetworkAddress

Operations shared across the network address value family.

Implementation Copy for AddressError

impl Copy for AddressError

Implementation Copy for Ipv4Address

impl Copy for Ipv4Address

Implementation Copy for Ipv6Address

impl Copy for Ipv6Address

Implementation Copy for IpAddress

impl Copy for IpAddress

Implementation Copy for Port

impl Copy for Port

Implementation Copy for Endpoint

impl Copy for Endpoint

Implementation Copy for DomainHost

impl Copy for DomainHost

Implementation Copy for Host

impl Copy for Host

Implementation Display for Ipv4Address

impl Display for Ipv4Address

Operation display

display = Ipv4Address.impl@9.display

Implementation Display for Ipv6Address

impl Display for Ipv6Address

Operation display

display = Ipv6Address.impl@10.display

Implementation Display for IpAddress

impl Display for IpAddress

Operation display

display = IpAddress.impl@11.display

Implementation Display for DomainHost

impl Display for DomainHost

Operation display

display = DomainHost.impl@12.display

On this page

When to useDetailsGotchasAddressReasonEmptyInvalidCharacterInvalidComponentLeadingZeroComponentOverflowWrongComponentCountMultipleCompressionCompressionWithoutOmissionHostReasonEmptyNameNameTooLongEmptyLabelLabelTooLongNulNonAsciiInvalidCharacterEdgeHyphenInvalidALabelTrailingDotNumericFinalLabelUnsupportedHostFormIpvFutureZoneIdentifierEscapedHostUserInfoPortDelimiterUriDelimiterAddressErrorInvalidAddressField reasonField offsetInvalidHostField reasonField offsetInvalidPortField valueUnsupportedFormField formField offsetOutputTooSmallField requiredField availableIpv4AddressAssociated function Ipv4Address.fromOctetsAssociated function Ipv4Address.parseMethod Ipv4Address.octetsMethod Ipv4Address.equalsMethod Ipv4Address.formatIntoIpv6AddressAssociated function Ipv6Address.fromOctetsAssociated function Ipv6Address.parseMethod Ipv6Address.octetsMethod Ipv6Address.equalsMethod Ipv6Address.formatIntoIpAddressV4Field valueV6Field valueMethod IpAddress.isV4Method IpAddress.equalsMethod IpAddress.formatIntoPortAssociated function Port.makeAssociated function Port.fromU16Method Port.valueEndpointAssociated function Endpoint.makeMethod Endpoint.addressMethod Endpoint.portMethod Endpoint.equalsDomainHostAssociated function DomainHost.makeMethod DomainHost.bytesMethod DomainHost.lengthMethod DomainHost.equalsHostDomainField valueIpv4Field valueIpv6Field valueAssociated function Host.parseMethod Host.numericNetworkAddressImplementation Copy for AddressErrorImplementation Copy for Ipv4AddressImplementation Copy for Ipv6AddressImplementation Copy for IpAddressImplementation Copy for PortImplementation Copy for EndpointImplementation Copy for DomainHostImplementation Copy for HostImplementation Display for Ipv4AddressOperation displayImplementation Display for Ipv6AddressOperation displayImplementation Display for IpAddressOperation displayImplementation Display for DomainHostOperation display