Silk

silk/uri

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.

Borrowed RFC 3986 URIs, explicit ownership, and reusable relative-reference resolution.

When to use

Use parse when a scheme is required. Use silk.uri_reference for relative references. Use resolveInto to reuse output storage, or resolveOwned for an independent owner.

Details

Uri accepts the RFC URI production, including fragments. Parsing allocates nothing. Resolution removes literal path dot segments and preserves copied component spelling. These operations do not apply network, scheme, or normalization policy.

Import as Uri with import silk.uri { Uri }.

Public declarations: 2.

Uri

pub struct Uri<'text>

A parsed URI borrowing input text, with a required scheme and an optional fragment.

Details

Parsing and component access allocate nothing. The value cannot outlive its input.

Associated function Uri.parse

pub fn parse<'text>(text: string<'text>) -> silk/result.Result<silk/uri.Uri<'text>, silk/uri_reference.ParseError>

Validates and borrows a scheme-bearing URI without allocating or normalizing.

Details

A missing scheme returns MissingScheme at byte zero. Other syntax errors identify their component and byte. The returned view retains the input lifetime.

Method Uri.copy

pub effect<'env> fn copy<'text: 'env, 'life1: 'env, 'env>(self: &'life1 Uri<'text>) -> OwnedUri ! OutOfMemoryError ? &mut Allocator

Copies this parsed URI into independently owned storage with one allocation for its text.

Associated function Uri.parseOwned

pub effect<'text> fn parseOwned<'text>(text: string<'text>) -> silk/result.Result<silk/uri.OwnedUri, silk/uri_reference.ParseError> ! OutOfMemoryError ? &mut Allocator

Validates input and explicitly copies it into owned storage; invalid input does not allocate.

Method Uri.format

pub fn format<'text, 'life1>(self: &'life1 Uri<'text>) -> string<'text>

Borrows the original URI text with delimiters, letter case, and escape spelling unchanged.

Method Uri.asReference

pub fn asReference<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/uri_reference.UriReference<'text>

Returns this scheme-bearing URI as a borrowed generic reference without validation or allocation.

Method Uri.scheme

pub fn scheme<'text, 'life1>(self: &'life1 Uri<'text>) -> string<'text>

Borrows the required scheme without its colon and preserves its letter case.

Method Uri.authority

pub fn authority<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows the authority without //, or returns None when absent. An empty authority remains present.

Method Uri.userinfo

pub fn userinfo<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows userinfo without @, or returns None when absent. An empty userinfo remains present.

Method Uri.host

pub fn host<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows the host, including IP-literal brackets, or returns None without authority. An empty host remains present.

Method Uri.hostKind

pub fn hostKind<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<silk/uri_reference.HostKind>

Returns the parsed host classification, or None when authority is absent.

Method Uri.port

pub fn port<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows the port digits without the colon, or returns None when absent. An empty port remains present.

Method Uri.path

pub fn path<'text, 'life1>(self: &'life1 Uri<'text>) -> string<'text>

Borrows the path with its escape spelling unchanged. The path can be empty.

Method Uri.query

pub fn query<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows the query without ?, or returns None when absent. An empty query remains present.

Method Uri.fragment

pub fn fragment<'text, 'life1>(self: &'life1 Uri<'text>) -> silk/option.Option<string<'text>>

Borrows the fragment without #, or returns None when absent. An empty fragment remains present.

Associated function Uri.resolveInto

pub effect<'env> fn resolveInto<'life1: 'env, 'life2: 'env, 'life3: 'env, 'life4: 'env, 'life5: 'env, 'env>(output: &'life1 mut silk/bytes.Bytes, base: &'life2 silk/uri.Uri<'life3>, reference: &'life4 silk/uri_reference.UriReference<'life5>) -> silk/result.Result<(), silk/uri_reference.ParseError> ! OutOfMemoryError ? &mut Allocator

Resolves into reusable byte storage with strict RFC 3986 section 5.2 semantics.

Details

Replaces output after reserving sufficient capacity. A single backing buffer holds the selected components and the path is compacted directly in it. Existing sufficient capacity allocates nothing. Allocation failure leaves the destination unchanged. Success returns unit; parse its ASCII byte view with parse to obtain a borrowed URI without allocating.

Gotchas

Output cannot overlap the borrowed inputs. Dot removal may expose // as authority syntax; invalid recomposition returns a syntax error and leaves the attempted serialization in output.

Associated function Uri.resolveOwned

pub effect<'env> fn resolveOwned<'life1: 'env, 'life2: 'env, 'life3: 'env, 'life4: 'env, 'env>(base: &'life1 silk/uri.Uri<'life2>, reference: &'life3 silk/uri_reference.UriReference<'life4>) -> silk/result.Result<silk/uri.OwnedUri, silk/uri_reference.ParseError> ! OutOfMemoryError ? &mut Allocator

Resolves with one owned backing allocation and adopts the completed serialization without copying.

Details

Reserves a calculated upper bound once. The final allocation may have spare capacity after dot removal. Use resolveInto when the caller already has reusable storage. Recomposition validation and its syntax-failure behavior are the same as resolveInto.

Implementation Copy for silk/uri.Uri<'text>

impl Copy for silk/uri.Uri<'text>

OwnedUri

pub struct OwnedUri

An immutable owned URI whose borrowed views cannot outlive its storage.

Associated function OwnedUri.fromString

pub fn fromString(text: String) -> silk/result.Result<silk/uri.OwnedUri, silk/uri_reference.ParseError>

Validates and adopts existing owned text without allocation or copying.

Gotchas

Consumes the supplied String on success and failure. A scheme is required.

Method OwnedUri.view

pub fn view<'life0>(self: &'life0 OwnedUri) -> silk/uri.Uri<'life0>

Borrows a parsed URI directly from the stored ranges without reparsing or allocating.

Method OwnedUri.intoString

pub fn intoString(self: OwnedUri) -> String

Transfers the owned serialization out of this URI without copying or allocating.

On this page