Crate url
rust-url is an implementation of the URL Standard for the Rust programming language.
URL parsing and data structures
First, URL parsing may fail for various reasons and therefore returns a Result.
use ;
assert!
Let’s parse a valid URL and look at its components.
use ;
# use ParseError;
#
# run.unwrap;
Some URLs are said to be cannot-be-a-base: they don’t have a username, password, host, or port, and their "path" is an arbitrary string rather than slash-separated segments:
use Url;
# use ParseError;
#
# run.unwrap;
Default Features
Versions <= 2.5.2 of the crate have no default features. Versions > 2.5.2 have the default feature 'std'.
If you are upgrading across this boundary and you have specified default-features = false, then
you will need to add the 'std' feature or the 'alloc' feature to your dependency.
The 'std' feature has the same behavior as the previous versions. The 'alloc' feature
provides no_std support.
Serde
Enable the serde feature to include Deserialize and Serialize implementations for url::Url.
Base URL
Many contexts allow URL references that can be relative to a base URL:
Since parsed URLs are absolute, giving a base is required for parsing relative URLs:
use ;
assert!
Use the join method on an Url to use it as a base URL:
use Url;
# use ParseError;
#
# run.unwrap;
Feature: serde
If you enable the serde feature, Url will implement
serde::Serialize and
serde::Deserialize.
See serde documentation for more information.
url = { version = "2", features = ["serde"] }
Feature: debugger_visualizer
If you enable the debugger_visualizer feature, the url crate will include
a natvis file
for Visual Studio that allows you to view
Url objects in the debugger.
This feature requires Rust 1.71 or later.
url = { version = "2", features = ["debugger_visualizer"] }
Modules
Structs
- OpaqueOrigin Opaque identifier for URLs that have file or other schemes
- ParseOptions Full configuration for the URL parser.
- PathSegmentsMut Exposes methods to manipulate the path of an URL that is not cannot-be-base.
- Url A parsed URL record.
-
UrlQuery
Implementation detail of
Url::query_pairs_mut. Typically not used directly.
Enums
- Host The host name of an URL.
- Origin The origin of an URL
- ParseError Errors that can occur during parsing.
- Position Indicates a position within a URL based on its components.
- SyntaxViolation Non-fatal syntax violations that can occur during parsing.