Skip to content
CryoCryo home
Stdlibnet::addr

url

import std::net::addr::url; · source

Types

Url

type struct Url {
    scheme:   Str;
    host:     Str;
    port:     u16;
    path:     Str;
    query:    Option<Str>;
    fragment: Option<Str>;

    static parse(source: Str) -> Result<Url, UrlError>;
    static byte0(s: Str) -> u8;
    static parse_port(digits: Str) -> Result<u16, UrlError>;
}

Url::parse reads absolute URLs — scheme://host:port/path?query#frag — into borrowed parts. path is never empty ("/" when the URL had none); query and fragment come back without their leading ? and #. A missing port falls back to the scheme's well-known default — 80 for http, 443 for https — and to 0 for a scheme it does not know.

Properties

PropertyType
schemeStr
hostStr
portu16
pathStr
queryOption<Str>
fragmentOption<Str>

Constructors

static parse(source: Str) -> Result<Url, UrlError>;

Parse an absolute URL. See the module docs for the accepted shape.

Static functions

static byte0(s: Str) -> u8;

s's first byte (callers guard !s.is_empty() first).

static parse_port(digits: Str) -> Result<u16, UrlError>;

Parse a non-empty decimal port into a u16.

UrlError

type enum UrlError {
    MissingScheme;
    EmptyScheme;
    EmptyHost;
    InvalidPort;
}

implement enum UrlError {
    message(&this) -> Str;
}

The four ways a URL can fail to parse; message() is the human-readable form.

It is a standalone parser. Parts come back verbatim — no %XX decoding, no ./.. collapsing — and http::Client still takes a SocketAddr plus a path, so wiring a Url-accepting client entry point is a remaining integration step.

Variants
VariantNotes
MissingSchemeNo scheme:// - the input is not an absolute URL.
EmptySchemeA :// with nothing before it.
EmptyHostThe authority had no host (scheme:///path, scheme://:80).
InvalidPortA :port that was empty, non-numeric, or out of u16 range.
Methods
message(&this) -> Str;

A short human-readable reason, for diagnostics.

Constants

const COLON:    u8 = 0x3A;
const SLASH:    u8 = 0x2F;
const QUESTION: u8 = 0x3F;
const HASH:     u8 = 0x23;
const AT:       u8 = 0x40;
const LBRACKET: u8 = 0x5B;
const RBRACKET: u8 = 0x5D;