Struct hyper::Url [−][src]
pub struct Url {
pub scheme: String,
pub scheme_data: SchemeData,
pub query: Option<String>,
pub fragment: Option<String>,
}The parsed representation of an absolute URL.
Fields
scheme: String
The scheme (a.k.a. protocol) of the URL, in ASCII lower case.
scheme_data: SchemeData
The components of the URL whose representation depends on where the scheme is relative.
query: Option<String>
The query string of the URL.
None if the ? delimiter character was not part of the parsed input,
otherwise a possibly empty, percent-encoded string.
Percent encoded strings are within the ASCII range.
See also the query_pairs, set_query_from_pairs,
and lossy_percent_decode_query methods.
fragment: Option<String>
The fragment identifier of the URL.
None if the # delimiter character was not part of the parsed input,
otherwise a possibly empty, percent-encoded string.
Percent encoded strings are within the ASCII range.
See also the lossy_percent_decode_fragment method.
Methods
impl Url[src]
impl Urlpub fn parse(input: &str) -> Result<Url, ParseError>[src]
pub fn parse(input: &str) -> Result<Url, ParseError>Parse an URL with the default UrlParser parameters.
In particular, relative URL references are parse errors since no base URL is provided.
pub fn from_file_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>, [src]
pub fn from_file_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>, Convert a file name as std::path::Path into an URL in the file scheme.
This returns Err if the given path is not absolute
or, with a Windows path, if the prefix is not a disk prefix (e.g. C:).
pub fn from_directory_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>, [src]
pub fn from_directory_path<P>(path: P) -> Result<Url, ()> where
P: AsRef<Path>, Convert a directory name as std::path::Path into an URL in the file scheme.
This returns Err if the given path is not absolute
or, with a Windows path, if the prefix is not a disk prefix (e.g. C:).
Compared to from_file_path, this adds an empty component to the path
(or, in terms of URL syntax, adds a trailing slash)
so that the entire path is considered when using this URL as a base URL.
For example:
"index.html"parsed withUrl::from_directory_path(Path::new("/var/www"))as the base URL isfile:///var/www/index.html"index.html"parsed withUrl::from_file_path(Path::new("/var/www/"))as the base URL isfile:///var/index.html, which might not be what was intended.
(Note that Path::new removes any trailing slash.)
pub fn to_file_path(&self) -> Result<PathBuf, ()>[src]
pub fn to_file_path(&self) -> Result<PathBuf, ()>Assuming the URL is in the file scheme or similar,
convert its path to an absolute std::path::Path.
Note: This does not actually check the URL’s scheme,
and may give nonsensical results for other schemes.
It is the user’s responsibility to check the URL’s scheme before calling this.
let path = url.to_file_path();
Returns Err if the host is neither empty nor "localhost",
or if Path::new_opt() returns None.
(That is, if the percent-decoded path contains a NUL byte or,
for a Windows path, is not UTF-8.)
pub fn serialize(&self) -> String[src]
pub fn serialize(&self) -> StringReturn the serialization of this URL as a string.
pub fn origin(&self) -> Origin[src]
pub fn origin(&self) -> OriginReturn the origin of this URL (https://url.spec.whatwg.org/#origin)
pub fn serialize_no_fragment(&self) -> String[src]
pub fn serialize_no_fragment(&self) -> StringReturn the serialization of this URL, without the fragment identifier, as a string
pub fn non_relative_scheme_data(&self) -> Option<&str>[src]
pub fn non_relative_scheme_data(&self) -> Option<&str>If the URL is non-relative, return the string scheme data.
pub fn non_relative_scheme_data_mut(&mut self) -> Option<&mut String>[src]
pub fn non_relative_scheme_data_mut(&mut self) -> Option<&mut String>If the URL is non-relative, return a mutable reference to the string scheme data.
pub fn relative_scheme_data(&self) -> Option<&RelativeSchemeData>[src]
pub fn relative_scheme_data(&self) -> Option<&RelativeSchemeData>If the URL is in a relative scheme, return the structured scheme data.
pub fn relative_scheme_data_mut(&mut self) -> Option<&mut RelativeSchemeData>[src]
pub fn relative_scheme_data_mut(&mut self) -> Option<&mut RelativeSchemeData>If the URL is in a relative scheme, return a mutable reference to the structured scheme data.
pub fn username(&self) -> Option<&str>[src]
pub fn username(&self) -> Option<&str>If the URL is in a relative scheme, return its username.
pub fn username_mut(&mut self) -> Option<&mut String>[src]
pub fn username_mut(&mut self) -> Option<&mut String>If the URL is in a relative scheme, return a mutable reference to its username.
pub fn lossy_percent_decode_username(&self) -> Option<String>[src]
pub fn lossy_percent_decode_username(&self) -> Option<String>Percent-decode the URL’s username, if any.
This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.
pub fn password(&self) -> Option<&str>[src]
pub fn password(&self) -> Option<&str>If the URL is in a relative scheme, return its password, if any.
pub fn password_mut(&mut self) -> Option<&mut String>[src]
pub fn password_mut(&mut self) -> Option<&mut String>If the URL is in a relative scheme, return a mutable reference to its password, if any.
pub fn lossy_percent_decode_password(&self) -> Option<String>[src]
pub fn lossy_percent_decode_password(&self) -> Option<String>Percent-decode the URL’s password, if any.
This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.
pub fn serialize_userinfo(&mut self) -> Option<String>[src]
pub fn serialize_userinfo(&mut self) -> Option<String>Serialize the URL's username and password, if any.
Format: "
pub fn host(&self) -> Option<&Host>[src]
pub fn host(&self) -> Option<&Host>If the URL is in a relative scheme, return its structured host.
pub fn host_mut(&mut self) -> Option<&mut Host>[src]
pub fn host_mut(&mut self) -> Option<&mut Host>If the URL is in a relative scheme, return a mutable reference to its structured host.
pub fn domain(&self) -> Option<&str>[src]
pub fn domain(&self) -> Option<&str>If the URL is in a relative scheme and its host is a domain, return the domain as a string.
pub fn domain_mut(&mut self) -> Option<&mut String>[src]
pub fn domain_mut(&mut self) -> Option<&mut String>If the URL is in a relative scheme and its host is a domain, return a mutable reference to the domain string.
pub fn serialize_host(&self) -> Option<String>[src]
pub fn serialize_host(&self) -> Option<String>If the URL is in a relative scheme, serialize its host as a string.
A domain a returned as-is, an IPv6 address between [] square brackets.
pub fn port(&self) -> Option<u16>[src]
pub fn port(&self) -> Option<u16>If the URL is in a relative scheme and has a port number, return it.
pub fn port_mut(&mut self) -> Option<&mut Option<u16>>[src]
pub fn port_mut(&mut self) -> Option<&mut Option<u16>>If the URL is in a relative scheme, return a mutable reference to its port.
pub fn port_or_default(&self) -> Option<u16>[src]
pub fn port_or_default(&self) -> Option<u16>If the URL is in a relative scheme that is not a file-like, return its port number, even if it is the default.
pub fn path(&self) -> Option<&[String]>[src]
pub fn path(&self) -> Option<&[String]>If the URL is in a relative scheme, return its path components.
pub fn path_mut(&mut self) -> Option<&mut Vec<String>>[src]
pub fn path_mut(&mut self) -> Option<&mut Vec<String>>If the URL is in a relative scheme, return a mutable reference to its path components.
pub fn serialize_path(&self) -> Option<String>[src]
pub fn serialize_path(&self) -> Option<String>If the URL is in a relative scheme, serialize its path as a string.
The returned string starts with a "/" slash, and components are separated by slashes. A trailing slash represents an empty last component.
pub fn query_pairs(&self) -> Option<Vec<(String, String)>>[src]
pub fn query_pairs(&self) -> Option<Vec<(String, String)>>Parse the URL’s query string, if any, as application/x-www-form-urlencoded
and return a vector of (key, value) pairs.
pub fn set_query_from_pairs<I, K, V>(&mut self, pairs: I) where
I: IntoIterator,
K: AsRef<str>,
V: AsRef<str>,
<I as IntoIterator>::Item: Borrow<(K, V)>, [src]
pub fn set_query_from_pairs<I, K, V>(&mut self, pairs: I) where
I: IntoIterator,
K: AsRef<str>,
V: AsRef<str>,
<I as IntoIterator>::Item: Borrow<(K, V)>, Serialize an iterator of (key, value) pairs as application/x-www-form-urlencoded
and set it as the URL’s query string.
pub fn lossy_percent_decode_query(&self) -> Option<String>[src]
pub fn lossy_percent_decode_query(&self) -> Option<String>Percent-decode the URL’s query string, if any.
This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.
pub fn lossy_percent_decode_fragment(&self) -> Option<String>[src]
pub fn lossy_percent_decode_fragment(&self) -> Option<String>Percent-decode the URL’s fragment identifier, if any.
This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.
pub fn join(&self, input: &str) -> Result<Url, ParseError>[src]
pub fn join(&self, input: &str) -> Result<Url, ParseError>Join a path with a base URL.
Corresponds to the basic URL parser where self is the given base URL.
Trait Implementations
impl Ord for Url[src]
impl Ord for Urlfn cmp(&self, other: &Url) -> Ordering[src]
fn cmp(&self, other: &Url) -> OrderingThis method returns an Ordering between self and other. Read more
fn max(self, other: Self) -> Self1.21.0[src]
fn max(self, other: Self) -> SelfCompares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self1.21.0[src]
fn min(self, other: Self) -> SelfCompares and returns the minimum of two values. Read more
impl PartialOrd<Url> for Url[src]
impl PartialOrd<Url> for Urlfn partial_cmp(&self, other: &Url) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Url) -> Option<Ordering>This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Url) -> bool[src]
fn lt(&self, other: &Url) -> boolThis method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Url) -> bool[src]
fn le(&self, other: &Url) -> boolThis method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Url) -> bool[src]
fn gt(&self, other: &Url) -> boolThis method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Url) -> bool[src]
fn ge(&self, other: &Url) -> boolThis method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl FromStr for Url[src]
impl FromStr for Urltype Err = ParseError
The associated error which can be returned from parsing.
fn from_str(url: &str) -> Result<Url, ParseError>[src]
fn from_str(url: &str) -> Result<Url, ParseError>Parses a string s to return a value of this type. Read more
impl Display for Url[src]
impl Display for Urlfn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>[src]
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error>Formats the value using the given formatter. Read more
impl Decodable for Url[src]
impl Decodable for Urlfn decode<D>(decoder: &mut D) -> Result<Url, <D as Decoder>::Error> where
D: Decoder, [src]
fn decode<D>(decoder: &mut D) -> Result<Url, <D as Decoder>::Error> where
D: Decoder, Deserialize a value using a Decoder.
impl Eq for Url[src]
impl Eq for Urlimpl Hash for Url[src]
impl Hash for Urlfn hash<__H>(&self, state: &mut __H) where
__H: Hasher, [src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher, Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl Encodable for Url[src]
impl Encodable for Urlfn encode<S>(&self, encoder: &mut S) -> Result<(), <S as Encoder>::Error> where
S: Encoder, [src]
fn encode<S>(&self, encoder: &mut S) -> Result<(), <S as Encoder>::Error> where
S: Encoder, Serialize a value using an Encoder.
impl PartialEq<Url> for Url[src]
impl PartialEq<Url> for Urlfn eq(&self, other: &Url) -> bool[src]
fn eq(&self, other: &Url) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Url) -> bool[src]
fn ne(&self, other: &Url) -> boolThis method tests for !=.
impl Clone for Url[src]
impl Clone for Urlfn clone(&self) -> Url[src]
fn clone(&self) -> UrlReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for Url[src]
impl Debug for Urlfn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>Formats the value using the given formatter. Read more
impl IntoUrl for Url[src]
impl IntoUrl for Url