Stdlibnet::addr
url
import std::net::addr::url; · source
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.
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.