Expand description
sorug — a blazingly fast, zero-allocation-preferred, WHATWG-compliant URL parser.
§Design
- Index-based record: component boundaries live as
u32offsets into the WHATWGhrefserialization, keeping the struct small and cache-friendly. - Lazy / CoW serialization: when the input is already canonical ASCII,
Urlborrows it with zero heap allocations; the first required mutation upgrades to an owned buffer. Cowon demand: percent-decoding helpers allocate only when needed.- SIMD delimiter scans:
memchron hot path segments. - Strict WHATWG state machine: transitions follow the URL Living Standard.
§Crate features
std(default): enablesstd::error::ErrorforParseError,memchr’s std backend, and file-path / socket helpers.serde: serialize / deserializeUrlas an href string.http: convert betweenUrlandhttp::Uri(impliesstd).
§Migration from 0.4
Additive (non-breaking):
SearchParams::has_value/SearchParams::delete_value/SearchParams::size- FFI:
sorug_set_username/sorug_set_password/sorug_set_host
§Migration from 0.3
Origin::Opaquenow wrapsOpaqueOrigin; useOrigin::new_opaque. Distinct opaque origins no longer compare equal.- New (
std):Url::from_file_path,Url::from_directory_path,Url::to_file_path,Url::set_ip_host,Url::socket_addrs. SearchParams::sort,Url::parse_with_params.
§API stability (pre-1.0)
Url<'a>borrows the input serialization when it is already canonical; callUrl::into_ownedbefore storing across mutations of the source.Backingis public for advanced introspection; preferUrl::as_str.- [
State] is#[doc(hidden)]andnon_exhaustive— not part of the stability promise. - See the README Semver and MSRV policy and 1.0 freeze checklist.
§Migration from 0.2
Url::join,Url::make_relative,Url::path_segments,Url::path_segments_mut,Url::query_pairs,Url::query_pairs_mut,Url::host_parsed,AsRef<str>, andcore::str::FromStr.- Optional features:
serde,http; disablestdwithdefault-features = falseforno_std+alloc. - Public
Hostenum (Domain/Ipv4/Ipv6) withHost::parse. UrlFlags::HOST_IDNAis set when the serialized host contains an ACE label (xn--).- Port API:
Url::set_porttakesOption<u16>(rust-url shape); quirks/WPT string setter isUrl::set_port_str.
Structs§
- Opaque
Origin - Opaque identifier for non-tuple origins (
file:,data:, failedblob:, …). - Path
Segments Mut - Exposes methods to manipulate the path of a URL that is not cannot-be-a-base.
- Query
Pairs Mut - Mutable view of a URL’s query as name/value pairs.
- Search
Params - A list of name/value pairs in
application/x-www-form-urlencodedsyntax. - Search
Params Iter - Iterator over borrowed
(name, value)pairs fromSearchParams. - Url
- A parsed URL record backed by its WHATWG serialization (
href). - UrlFlags
- Compact boolean attributes of a parsed URL record.
Enums§
- Backing
- Storage for the WHATWG
hrefserialization. - Host
- A parsed URL host: domain name, IPv4, or IPv6.
- Origin
- A URL origin: either an
opaque origin or a
(scheme, host, port)tuple. - Parse
Error - Failure modes of
Url::parse/ the basic URL parser.
Functions§
- parse_
urlencoded - Parse
application/x-www-form-urlencodedbytes into decoded name/value pairs. - serialize_
urlencoded - Serialize pairs as
application/x-www-form-urlencoded. - uri_
to_ url http - Parse an
http::Uriinto an ownedUrl.