Lyricdev
GitHub

struct Uri

pub struct Uri :: [Equatable, Hashable, Debug]

Conforms to Equatable, Hashable, Debug, Display, Parse, Codable.

A URI reference (§4.1): absolute where it has a scheme, relative otherwise. The host is held without its brackets — show puts them around an address with a : —; a null host means no authority, an empty one the empty authority of file:///etc. port is null where none or an empty one was written.

Fields

pub scheme: ?string = null
pub userinfo: ?string = null
pub host: ?string = null
pub port: ?int = null
pub path: string = ""
pub query: ?string = null
pub fragment: ?string = null

Methods

pub fn isAbsolute(): bool

Returns whether the reference has a scheme (§4.3).

pub fn authority(): ?string

Returns the authority as written between // and the path, null where there is none.

pub fn queryPairs(): Query throws ParseError

Returns the query as its pairs, empty where there is no query.

Errors

Throws ParseError as Query.parse does.

pub fn resolve(ref: Uri): Uri

Returns ref resolved against this base (§5.2.2, strict: a reference with the base's scheme is absolute). The base should be absolute (§5.2.1); a relative base gives a relative result.

pub fn normalize(): Uri

Returns the URI normalized (§6.2): the scheme and the host in small letters, a percent-encoding of an unreserved character decoded and the others' digits in capitals, the dot segments of the path removed, an empty path with an authority made /, and the scheme's default port dropped (80 for http and ws, 443 for https and wss, 21 for ftp).

fn show(): string

Returns the parts recomposed into the reference's text (§5.3).

static fn parse(s: StringView): Uri throws ParseError

Parses a URI reference as §3 and appendix B split it: the scheme up to the first : where its characters are a scheme's and no /, ? or # comes first; the authority after // up to the next /, ? or #, split at the last @ and the port's :, a host in brackets an IPv6 address; the path up to ? or #; the query up to #; the fragment. Every part is checked against its grammar. An empty text is the empty reference (§4.4): Uri.parse("") is Uri {}.

Errors

Throws ParseError with kind Invalid for a part that does not match its grammar, a port that is not digits or beyond 65535, an unclosed bracket, and a : in the first segment of a relative path.

fn encode<E :: [Encoder]>(&e: E): void throws EncodeError
static fn decode<D :: [Decoder]>(&d: D): Uri throws DecodeError