Expand description
URL manipulation library with an API inspired by Python’s yarl.
Url is an immutable, cheaply cloneable, normalized URL reference stored
in a single ByteString. Accessors return
borrowed, percent-encoded components with methods to decode them;
modifications return or produce a new normalized URL.
use urly::Url;
let url = Url::from_static("https://example.com/api/v1?page=2");
assert_eq!(url.host(), Some("example.com"));
assert_eq!(url.port_or_known_default(), Some(443));
let users = &url / "users" / "john doe";
assert_eq!(users, "https://example.com/api/v1/users/john%20doe");
assert_eq!(users.path().segments().last().unwrap(), "john%20doe");
let mut url = users.join("../groups?id=1").unwrap();
url.extend_query_pairs([("sort", "name asc")]);
assert_eq!(url, "https://example.com/api/v1/groups?id=1&sort=name+asc");
let url = Url::builder()
.scheme("http")
.host("münchen.de")
.path("/a b")
.query_pair("q", "x&y")
.build()
.unwrap();
assert_eq!(url, "http://xn--mnchen-3ya.de/a%20b?q=x%26y");§Features
Modules§
- quoting
- Percent-encoding with the same rules as Python’s yarl.
Structs§
- Authority
- URL authority:
[userinfo "@"] host [":" port]. - Builder
- URL builder.
- Fragment
- Percent-encoded URL fragment, without the leading
#. - Invalid
Url - An error returned when a URL or URL component is invalid.
- Invalid
UrlParts - An error returned by
Url::from_parts. - Parts
- Percent-encoded URL parts.
- Path
- Percent-encoded URL path.
- Path
AndQuery - Path with an optional query:
path ["?" query]. - Port
- URL port.
- Query
- Percent-encoded URL query, without the leading
?. - Query
Pairs - Iterator over decoded query pairs, see
Query::pairs. - Scheme
- URL scheme, e.g.
https. - Segments
- Iterator over percent-encoded path segments, see
Path::segments. - Url
- Normalized URL reference.
- User
Info - URL userinfo:
user [":" password], percent-encoded.