blob: d833791af4994cb5937f308156c343cd2642b425 [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A parsed URL record."><meta name="keywords" content="rust, rustlang, rust-lang, Url"><title>Url in url - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../url/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../url/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Url</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.as_str">as_str</a></li><li><a href="#method.cannot_be_a_base">cannot_be_a_base</a></li><li><a href="#method.deserialize_internal">deserialize_internal</a></li><li><a href="#method.domain">domain</a></li><li><a href="#method.fragment">fragment</a></li><li><a href="#method.from_directory_path">from_directory_path</a></li><li><a href="#method.from_file_path">from_file_path</a></li><li><a href="#method.has_authority">has_authority</a></li><li><a href="#method.has_host">has_host</a></li><li><a href="#method.host">host</a></li><li><a href="#method.host_str">host_str</a></li><li><a href="#method.into_string">into_string</a></li><li><a href="#method.join">join</a></li><li><a href="#method.make_relative">make_relative</a></li><li><a href="#method.options">options</a></li><li><a href="#method.origin">origin</a></li><li><a href="#method.parse">parse</a></li><li><a href="#method.parse_with_params">parse_with_params</a></li><li><a href="#method.password">password</a></li><li><a href="#method.path">path</a></li><li><a href="#method.path_segments">path_segments</a></li><li><a href="#method.path_segments_mut">path_segments_mut</a></li><li><a href="#method.port">port</a></li><li><a href="#method.port_or_known_default">port_or_known_default</a></li><li><a href="#method.query">query</a></li><li><a href="#method.query_pairs">query_pairs</a></li><li><a href="#method.query_pairs_mut">query_pairs_mut</a></li><li><a href="#method.scheme">scheme</a></li><li><a href="#method.serialize_internal">serialize_internal</a></li><li><a href="#method.set_fragment">set_fragment</a></li><li><a href="#method.set_host">set_host</a></li><li><a href="#method.set_ip_host">set_ip_host</a></li><li><a href="#method.set_password">set_password</a></li><li><a href="#method.set_path">set_path</a></li><li><a href="#method.set_port">set_port</a></li><li><a href="#method.set_query">set_query</a></li><li><a href="#method.set_scheme">set_scheme</a></li><li><a href="#method.set_username">set_username</a></li><li><a href="#method.socket_addrs">socket_addrs</a></li><li><a href="#method.to_file_path">to_file_path</a></li><li><a href="#method.username">username</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsRef%3Cstr%3E-for-Url">AsRef&lt;str&gt;</a></li><li><a href="#impl-Clone-for-Url">Clone</a></li><li><a href="#impl-Debug-for-Url">Debug</a></li><li><a href="#impl-Deserialize%3C%27de%3E-for-Url">Deserialize&lt;&#39;de&gt;</a></li><li><a href="#impl-Display-for-Url">Display</a></li><li><a href="#impl-Eq-for-Url">Eq</a></li><li><a href="#impl-From%3CUrl%3E-for-String">From&lt;Url&gt;</a></li><li><a href="#impl-FromStr-for-Url">FromStr</a></li><li><a href="#impl-Hash-for-Url">Hash</a></li><li><a href="#impl-Index%3CRange%3CPosition%3E%3E-for-Url">Index&lt;Range&lt;Position&gt;&gt;</a></li><li><a href="#impl-Index%3CRangeFrom%3CPosition%3E%3E-for-Url">Index&lt;RangeFrom&lt;Position&gt;&gt;</a></li><li><a href="#impl-Index%3CRangeFull%3E-for-Url">Index&lt;RangeFull&gt;</a></li><li><a href="#impl-Index%3CRangeTo%3CPosition%3E%3E-for-Url">Index&lt;RangeTo&lt;Position&gt;&gt;</a></li><li><a href="#impl-Ord-for-Url">Ord</a></li><li><a href="#impl-PartialEq%3CUrl%3E-for-Url">PartialEq&lt;Url&gt;</a></li><li><a href="#impl-PartialOrd%3CUrl%3E-for-Url">PartialOrd&lt;Url&gt;</a></li><li><a href="#impl-Serialize-for-Url">Serialize</a></li><li><a href="#impl-TryFrom%3C%26%27a%20str%3E-for-Url">TryFrom&lt;&amp;&#39;a str&gt;</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-Url">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Url">Send</a></li><li><a href="#impl-Sync-for-Url">Sync</a></li><li><a href="#impl-Unpin-for-Url">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Url">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-Url">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-Url">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-Url">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-DeserializeOwned-for-Url">DeserializeOwned</a></li><li><a href="#impl-From%3CT%3E-for-Url">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-Url">Into&lt;U&gt;</a></li><li><a href="#impl-ToOwned-for-Url">ToOwned</a></li><li><a href="#impl-ToString-for-Url">ToString</a></li><li><a href="#impl-TryFrom%3CU%3E-for-Url">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-Url">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In url</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="index.html">url</a>::<wbr><a class="struct" href="#">Url</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/url/lib.rs.html#170-192">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct Url { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A parsed URL record.</p>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#256-2505">source</a><a href="#impl-Url" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.parse" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#279-281">source</a><h4 class="code-header">pub fn <a href="#method.parse" class="fnname">parse</a>(input: &amp;str) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a>&gt;</h4></section></summary><div class="docblock"><p>Parse an absolute URL from a string.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.net&quot;</span>)<span class="question-mark">?</span>;</code></pre></div>
<h5 id="errors"><a href="#errors">Errors</a></h5>
<p>If the function can not parse an absolute URL from the given string,
a <a href="enum.ParseError.html"><code>ParseError</code></a> variant will be returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.parse_with_params" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#309-323">source</a><h4 class="code-header">pub fn <a href="#method.parse_with_params" class="fnname">parse_with_params</a>&lt;I, K, V&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;input: &amp;str,<br>&nbsp;&nbsp;&nbsp;&nbsp;iter: I<br>) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: IntoIterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;I::Item: Borrow&lt;(K, V)&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;K: AsRef&lt;str&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: AsRef&lt;str&gt;,</span></h4></section></summary><div class="docblock"><p>Parse an absolute URL from a string and add params to its query string.</p>
<p>Existing params are not removed.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse_with_params(<span class="string">&quot;https://example.net?dont=clobberme&quot;</span>,
<span class="kw-2">&amp;</span>[(<span class="string">&quot;lang&quot;</span>, <span class="string">&quot;rust&quot;</span>), (<span class="string">&quot;browser&quot;</span>, <span class="string">&quot;servo&quot;</span>)])<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(<span class="string">&quot;https://example.net/?dont=clobberme&amp;lang=rust&amp;browser=servo&quot;</span>, url.as_str());</code></pre></div>
<h5 id="errors-1"><a href="#errors-1">Errors</a></h5>
<p>If the function can not parse an absolute URL from the given string,
a <a href="enum.ParseError.html"><code>ParseError</code></a> variant will be returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.join" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#360-362">source</a><h4 class="code-header">pub fn <a href="#method.join" class="fnname">join</a>(&amp;self, input: &amp;str) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a>&gt;</h4></section></summary><div class="docblock"><p>Parse a string as an URL, with this URL as the base URL.</p>
<p>The inverse of this is <a href="#method.make_relative"><code>make_relative</code></a>.</p>
<p>Note: a trailing slash is significant.
Without it, the last path component is considered to be a “file” name
to be removed to get at the “directory” that is used as the base:</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b.html&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = base.join(<span class="string">&quot;c.png&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.net/a/c.png&quot;</span>); <span class="comment">// Not /a/b.html/c.png
</span><span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b/&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = base.join(<span class="string">&quot;c.png&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.net/a/b/c.png&quot;</span>);</code></pre></div>
<h5 id="errors-2"><a href="#errors-2">Errors</a></h5>
<p>If the function can not parse an URL from the given string
with this URL as the base URL, a <a href="enum.ParseError.html"><code>ParseError</code></a> variant will be returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.make_relative" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#405-494">source</a><h4 class="code-header">pub fn <a href="#method.make_relative" class="fnname">make_relative</a>(&amp;self, url: &amp;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>) -&gt; Option&lt;String&gt;</h4></section></summary><div class="docblock"><p>Creates a relative URL if possible, with this URL as the base URL.</p>
<p>This is the inverse of <a href="#method.join"><code>join</code></a>.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b.html&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.net/a/c.png&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>relative = base.make_relative(<span class="kw-2">&amp;</span>url);
<span class="macro">assert_eq!</span>(relative.as_ref().map(|s| s.as_str()), <span class="prelude-val">Some</span>(<span class="string">&quot;c.png&quot;</span>));
<span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b/&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.net/a/b/c.png&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>relative = base.make_relative(<span class="kw-2">&amp;</span>url);
<span class="macro">assert_eq!</span>(relative.as_ref().map(|s| s.as_str()), <span class="prelude-val">Some</span>(<span class="string">&quot;c.png&quot;</span>));
<span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b/&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.net/a/d/c.png&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>relative = base.make_relative(<span class="kw-2">&amp;</span>url);
<span class="macro">assert_eq!</span>(relative.as_ref().map(|s| s.as_str()), <span class="prelude-val">Some</span>(<span class="string">&quot;../d/c.png&quot;</span>));
<span class="kw">let </span>base = Url::parse(<span class="string">&quot;https://example.net/a/b.html?c=d&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.net/a/b.html?e=f&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>relative = base.make_relative(<span class="kw-2">&amp;</span>url);
<span class="macro">assert_eq!</span>(relative.as_ref().map(|s| s.as_str()), <span class="prelude-val">Some</span>(<span class="string">&quot;?e=f&quot;</span>));</code></pre></div>
<h5 id="errors-3"><a href="#errors-3">Errors</a></h5>
<p>If this URL can’t be a base for the given URL, <code>None</code> is returned.
This is for example the case if the scheme, host or port are not the same.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.options" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#515-521">source</a><h4 class="code-header">pub fn <a href="#method.options" class="fnname">options</a>&lt;'a&gt;() -&gt; <a class="struct" href="struct.ParseOptions.html" title="struct url::ParseOptions">ParseOptions</a>&lt;'a&gt;</h4></section></summary><div class="docblock"><p>Return a default <code>ParseOptions</code> that can fully configure the URL parser.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<p>Get default <code>ParseOptions</code>, then change base url</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>options = Url::options();
<span class="kw">let </span>api = Url::parse(<span class="string">&quot;https://api.example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>base_url = options.base_url(<span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span>api));
<span class="kw">let </span>version_url = base_url.parse(<span class="string">&quot;version.json&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(version_url.as_str(), <span class="string">&quot;https://api.example.com/version.json&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_str" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#542-544">source</a><h4 class="code-header">pub fn <a href="#method.as_str" class="fnname">as_str</a>(&amp;self) -&gt; &amp;str</h4></section></summary><div class="docblock"><p>Return the serialization of this URL.</p>
<p>This is fast since that serialization is already stored in the <code>Url</code> struct.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url_str = <span class="string">&quot;https://example.net/&quot;</span>;
<span class="kw">let </span>url = Url::parse(url_str)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), url_str);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_string" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#566-568">source</a><h4 class="code-header">pub fn <a href="#method.into_string" class="fnname">into_string</a>(self) -&gt; String</h4></section><span class="item-info"><div class="stab deprecated"><span class="emoji">👎</span><span>Deprecated since 2.3.0: use Into&lt;String&gt;</span></div></span></summary><div class="docblock"><p>Return the serialization of this URL.</p>
<p>This consumes the <code>Url</code> and takes ownership of the <code>String</code> stored in it.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url_str = <span class="string">&quot;https://example.net/&quot;</span>;
<span class="kw">let </span>url = Url::parse(url_str)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(String::from(url), url_str);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.origin" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#765-767">source</a><h4 class="code-header">pub fn <a href="#method.origin" class="fnname">origin</a>(&amp;self) -&gt; <a class="enum" href="enum.Origin.html" title="enum url::Origin">Origin</a></h4></section></summary><div class="docblock"><p>Return the origin of this URL (<a href="https://url.spec.whatwg.org/#origin">https://url.spec.whatwg.org/#origin</a>)</p>
<p>Note: this returns an opaque origin for <code>file:</code> URLs, which causes
<code>url.origin() != url.origin()</code>.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<p>URL with <code>ftp</code> scheme:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Host, Origin, Url};
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://example.com/foo&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.origin(),
Origin::Tuple(<span class="string">&quot;ftp&quot;</span>.into(),
Host::Domain(<span class="string">&quot;example.com&quot;</span>.into()),
<span class="number">21</span>));</code></pre></div>
<p>URL with <code>blob</code> scheme:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Host, Origin, Url};
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;blob:https://example.com/foo&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.origin(),
Origin::Tuple(<span class="string">&quot;https&quot;</span>.into(),
Host::Domain(<span class="string">&quot;example.com&quot;</span>.into()),
<span class="number">443</span>));</code></pre></div>
<p>URL with <code>file</code> scheme:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Host, Origin, Url};
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;file:///tmp/foo&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.origin().is_tuple());
<span class="kw">let </span>other_url = Url::parse(<span class="string">&quot;file:///tmp/foo&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.origin() != other_url.origin());</code></pre></div>
<p>URL with other scheme:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Host, Origin, Url};
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;foo:bar&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.origin().is_tuple());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.scheme" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#785-787">source</a><h4 class="code-header">pub fn <a href="#method.scheme" class="fnname">scheme</a>(&amp;self) -&gt; &amp;str</h4></section></summary><div class="docblock"><p>Return the scheme of this URL, lower-cased, as an ASCII string without the ‘:’ delimiter.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;file:///tmp/foo&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.scheme(), <span class="string">&quot;file&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.has_authority" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#815-818">source</a><h4 class="code-header">pub fn <a href="#method.has_authority" class="fnname">has_authority</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Return whether the URL has an ‘authority’,
which can contain a username, password, host, and port number.</p>
<p>URLs that do <em>not</em> are either path-only like <code>unix:/run/foo.socket</code>
or cannot-be-a-base like <code>data:text/plain,Stuff</code>.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.has_authority());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;unix:/run/foo.socket&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.has_authority());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,Stuff&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.has_authority());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cannot_be_a_base" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#846-848">source</a><h4 class="code-header">pub fn <a href="#method.cannot_be_a_base" class="fnname">cannot_be_a_base</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Return whether this URL is a cannot-be-a-base URL,
meaning that parsing a relative URL string with this URL as the base will return an error.</p>
<p>This is the case if the scheme and <code>:</code> delimiter are not followed by a <code>/</code> slash,
as is typically the case of <code>data:</code> and <code>mailto:</code> URLs.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.cannot_be_a_base());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;unix:/run/foo.socket&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.cannot_be_a_base());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,Stuff&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.cannot_be_a_base());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.username" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#872-879">source</a><h4 class="code-header">pub fn <a href="#method.username" class="fnname">username</a>(&amp;self) -&gt; &amp;str</h4></section></summary><div class="docblock"><p>Return the username for this URL (typically the empty string)
as a percent-encoded ASCII string.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.username(), <span class="string">&quot;rms&quot;</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://:secret123@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.username(), <span class="string">&quot;&quot;</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.username(), <span class="string">&quot;&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.password" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#905-917">source</a><h4 class="code-header">pub fn <a href="#method.password" class="fnname">password</a>(&amp;self) -&gt; Option&lt;&amp;str&gt;</h4></section></summary><div class="docblock"><p>Return the password for this URL, if any, as a percent-encoded ASCII string.</p>
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms:secret123@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">Some</span>(<span class="string">&quot;secret123&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://:secret123@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">Some</span>(<span class="string">&quot;secret123&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.has_host" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#940-942">source</a><h4 class="code-header">pub fn <a href="#method.has_host" class="fnname">has_host</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Equivalent to <code>url.host().is_some()</code>.</p>
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.has_host());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;unix:/run/foo.socket&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.has_host());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,Stuff&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(!url.has_host());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.host_str" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#977-983">source</a><h4 class="code-header">pub fn <a href="#method.host_str" class="fnname">host_str</a>(&amp;self) -&gt; Option&lt;&amp;str&gt;</h4></section></summary><div class="docblock"><p>Return the string representation of the host (domain or IP address) for this URL, if any.</p>
<p>Non-ASCII domains are punycode-encoded per IDNA if this is the host
of a special URL, or percent encoded for non-special URLs.
IPv6 addresses are given between <code>[</code> and <code>]</code> brackets.</p>
<p>Cannot-be-a-base URLs (typical of <code>data:</code> and <code>mailto:</code>) and some <code>file:</code> URLs
don’t have a host.</p>
<p>See also the <code>host</code> method.</p>
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://127.0.0.1/index.html&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.host_str(), <span class="prelude-val">Some</span>(<span class="string">&quot;127.0.0.1&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.host_str(), <span class="prelude-val">Some</span>(<span class="string">&quot;example.com&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;unix:/run/foo.socket&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.host_str(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,Stuff&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.host_str(), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.host" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1016-1023">source</a><h4 class="code-header">pub fn <a href="#method.host" class="fnname">host</a>(&amp;self) -&gt; Option&lt;<a class="enum" href="enum.Host.html" title="enum url::Host">Host</a>&lt;&amp;str&gt;&gt;</h4></section></summary><div class="docblock"><p>Return the parsed representation of the host for this URL.
Non-ASCII domain labels are punycode-encoded per IDNA if this is the host
of a special URL, or percent encoded for non-special URLs.</p>
<p>Cannot-be-a-base URLs (typical of <code>data:</code> and <code>mailto:</code>) and some <code>file:</code> URLs
don’t have a host.</p>
<p>See also the <code>host_str</code> method.</p>
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://127.0.0.1/index.html&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.host().is_some());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ftp://rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.host().is_some());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;unix:/run/foo.socket&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.host().is_none());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,Stuff&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.host().is_none());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.domain" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1048-1053">source</a><h4 class="code-header">pub fn <a href="#method.domain" class="fnname">domain</a>(&amp;self) -&gt; Option&lt;&amp;str&gt;</h4></section></summary><div class="docblock"><p>If this URL has a host and it is a domain name (not an IP address), return it.
Non-ASCII domains are punycode-encoded per IDNA if this is the host
of a special URL, or percent encoded for non-special URLs.</p>
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://127.0.0.1/&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.domain(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;mailto:rms@example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.domain(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.domain(), <span class="prelude-val">Some</span>(<span class="string">&quot;example.com&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.port" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1080-1082">source</a><h4 class="code-header">pub fn <a href="#method.port" class="fnname">port</a>(&amp;self) -&gt; Option&lt;u16&gt;</h4></section></summary><div class="docblock"><p>Return the port number for this URL, if any.</p>
<p>Note that default port numbers are never reflected by the serialization,
use the <code>port_or_known_default()</code> method if you want a default port number returned.</p>
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com:443/&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;ssh://example.com:22&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port(), <span class="prelude-val">Some</span>(<span class="number">22</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.port_or_known_default" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1112-1114">source</a><h4 class="code-header">pub fn <a href="#method.port_or_known_default" class="fnname">port_or_known_default</a>(&amp;self) -&gt; Option&lt;u16&gt;</h4></section></summary><div class="docblock"><p>Return the port number for this URL, or the default port number if it is known.</p>
<p>This method only knows the default port number
of the <code>http</code>, <code>https</code>, <code>ws</code>, <code>wss</code> and <code>ftp</code> schemes.</p>
<p>For URLs in these schemes, this method always returns <code>Some(_)</code>.
For other schemes, it is the same as <code>Url::port()</code>.</p>
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;foo://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port_or_known_default(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;foo://example.com:1456&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port_or_known_default(), <span class="prelude-val">Some</span>(<span class="number">1456</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.port_or_known_default(), <span class="prelude-val">Some</span>(<span class="number">443</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.socket_addrs" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1143-1169">source</a><h4 class="code-header">pub fn <a href="#method.socket_addrs" class="fnname">socket_addrs</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;default_port_number: impl Fn() -&gt; Option&lt;u16&gt;<br>) -&gt; Result&lt;Vec&lt;SocketAddr&gt;&gt;</h4></section></summary><div class="docblock"><p>Resolve a URL’s host and port number to <code>SocketAddr</code>.</p>
<p>If the URL has the default port number of a scheme that is unknown to this library,
<code>default_port_number</code> provides an opportunity to provide the actual port number.
In non-example code this should be implemented either simply as <code>|| None</code>,
or by matching on the URL’s <code>.scheme()</code>.</p>
<p>If the host is a domain, it is resolved using the standard library’s DNS support.</p>
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>url = url::Url::parse(<span class="string">&quot;https://example.net/&quot;</span>).unwrap();
<span class="kw">let </span>addrs = url.socket_addrs(|| <span class="prelude-val">None</span>).unwrap();
std::net::TcpStream::connect(<span class="kw-2">&amp;*</span>addrs)</code></pre></div>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="doccomment">/// With application-specific known default port numbers
</span><span class="kw">fn </span>socket_addrs(url: url::Url) -&gt; std::io::Result&lt;Vec&lt;std::net::SocketAddr&gt;&gt; {
url.socket_addrs(|| <span class="kw">match </span>url.scheme() {
<span class="string">&quot;socks5&quot; </span>| <span class="string">&quot;socks5h&quot; </span>=&gt; <span class="prelude-val">Some</span>(<span class="number">1080</span>),
<span class="kw">_ </span>=&gt; <span class="prelude-val">None</span>,
})
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.path" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1194-1201">source</a><h4 class="code-header">pub fn <a href="#method.path" class="fnname">path</a>(&amp;self) -&gt; &amp;str</h4></section></summary><div class="docblock"><p>Return the path for this URL, as a percent-encoded ASCII string.
For cannot-be-a-base URLs, this is an arbitrary string that doesn’t start with ‘/’.
For other URLs, this starts with a ‘/’ slash
and continues with slash-separated path segments.</p>
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/api/versions?page=2&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/api/versions&quot;</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/&quot;</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/countries/việt nam&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/countries/vi%E1%BB%87t%20nam&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.path_segments" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1241-1244">source</a><h4 class="code-header">pub fn <a href="#method.path_segments" class="fnname">path_segments</a>(&amp;self) -&gt; Option&lt;Split&lt;'_, char&gt;&gt;</h4></section></summary><div class="docblock"><p>Unless this URL is cannot-be-a-base,
return an iterator of ‘/’ slash-separated path segments,
each as a percent-encoded ASCII string.</p>
<p>Return <code>None</code> for cannot-be-a-base URLs.</p>
<p>When <code>Some</code> is returned, the iterator always contains at least one string
(which may be empty).</p>
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/foo/bar&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>path_segments = url.path_segments().ok_or_else(|| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">Some</span>(<span class="string">&quot;foo&quot;</span>));
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">Some</span>(<span class="string">&quot;bar&quot;</span>));
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>path_segments = url.path_segments().ok_or_else(|| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">Some</span>(<span class="string">&quot;&quot;</span>));
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">None</span>);
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;data:text/plain,HelloWorld&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.path_segments().is_none());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/countries/việt nam&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>path_segments = url.path_segments().ok_or_else(|| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">Some</span>(<span class="string">&quot;countries&quot;</span>));
<span class="macro">assert_eq!</span>(path_segments.next(), <span class="prelude-val">Some</span>(<span class="string">&quot;vi%E1%BB%87t%20nam&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.query" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1270-1282">source</a><h4 class="code-header">pub fn <a href="#method.query" class="fnname">query</a>(&amp;self) -&gt; Option&lt;&amp;str&gt;</h4></section></summary><div class="docblock"><p>Return this URL’s query string, if any, as a percent-encoded ASCII string.</p>
<h5 id="examples-22"><a href="#examples-22">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">fn </span>run() -&gt; <span class="prelude-ty">Result</span>&lt;(), ParseError&gt; {
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/products?page=2&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>query = url.query();
<span class="macro">assert_eq!</span>(query, <span class="prelude-val">Some</span>(<span class="string">&quot;page=2&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/products&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>query = url.query();
<span class="macro">assert!</span>(query.is_none());
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/?country=español&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>query = url.query();
<span class="macro">assert_eq!</span>(query, <span class="prelude-val">Some</span>(<span class="string">&quot;country=espa%C3%B1ol&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.query_pairs" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1309-1311">source</a><h4 class="code-header">pub fn <a href="#method.query_pairs" class="fnname">query_pairs</a>(&amp;self) -&gt; <a class="struct" href="../form_urlencoded/struct.Parse.html" title="struct form_urlencoded::Parse">Parse</a>&lt;'_&gt;</h4></section></summary><div class="docblock"><p>Parse the URL’s query string, if any, as <code>application/x-www-form-urlencoded</code>
and return an iterator of (key, value) pairs.</p>
<h5 id="examples-23"><a href="#examples-23">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::borrow::Cow;
<span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/products?page=2&amp;sort=desc&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>pairs = url.query_pairs();
<span class="macro">assert_eq!</span>(pairs.count(), <span class="number">2</span>);
<span class="macro">assert_eq!</span>(pairs.next(), <span class="prelude-val">Some</span>((Cow::Borrowed(<span class="string">&quot;page&quot;</span>), Cow::Borrowed(<span class="string">&quot;2&quot;</span>))));
<span class="macro">assert_eq!</span>(pairs.next(), <span class="prelude-val">Some</span>((Cow::Borrowed(<span class="string">&quot;sort&quot;</span>), Cow::Borrowed(<span class="string">&quot;desc&quot;</span>))));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fragment" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1345-1350">source</a><h4 class="code-header">pub fn <a href="#method.fragment" class="fnname">fragment</a>(&amp;self) -&gt; Option&lt;&amp;str&gt;</h4></section></summary><div class="docblock"><p>Return this URL’s fragment identifier, if any.</p>
<p>A fragment is the part of the URL after the <code>#</code> symbol.
The fragment is optional and, if present, contains a fragment identifier
that identifies a secondary resource, such as a section heading
of a document.</p>
<p>In HTML, the fragment identifier is usually the id attribute of a an element
that is scrolled to on load. Browsers typically will not send the fragment portion
of a URL to the server.</p>
<p><strong>Note:</strong> the parser did <em>not</em> percent-encode this component,
but the input may have been percent-encoded already.</p>
<h5 id="examples-24"><a href="#examples-24">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/data.csv#row=4&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.fragment(), <span class="prelude-val">Some</span>(<span class="string">&quot;row=4&quot;</span>));
<span class="kw">let </span>url = Url::parse(<span class="string">&quot;https://example.com/data.csv#cell=4,1-6,2&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.fragment(), <span class="prelude-val">Some</span>(<span class="string">&quot;cell=4,1-6,2&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_fragment" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1382-1396">source</a><h4 class="code-header">pub fn <a href="#method.set_fragment" class="fnname">set_fragment</a>(&amp;mut self, fragment: Option&lt;&amp;str&gt;)</h4></section></summary><div class="docblock"><p>Change this URL’s fragment identifier.</p>
<h5 id="examples-25"><a href="#examples-25">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com/data.csv&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/data.csv&quot;</span>);
url.set_fragment(<span class="prelude-val">Some</span>(<span class="string">&quot;cell=4,1-6,2&quot;</span>));
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/data.csv#cell=4,1-6,2&quot;</span>);
<span class="macro">assert_eq!</span>(url.fragment(), <span class="prelude-val">Some</span>(<span class="string">&quot;cell=4,1-6,2&quot;</span>));
url.set_fragment(<span class="prelude-val">None</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/data.csv&quot;</span>);
<span class="macro">assert!</span>(url.fragment().is_none());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_query" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1435-1460">source</a><h4 class="code-header">pub fn <a href="#method.set_query" class="fnname">set_query</a>(&amp;mut self, query: Option&lt;&amp;str&gt;)</h4></section></summary><div class="docblock"><p>Change this URL’s query string.</p>
<h5 id="examples-26"><a href="#examples-26">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com/products&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/products&quot;</span>);
url.set_query(<span class="prelude-val">Some</span>(<span class="string">&quot;page=2&quot;</span>));
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/products?page=2&quot;</span>);
<span class="macro">assert_eq!</span>(url.query(), <span class="prelude-val">Some</span>(<span class="string">&quot;page=2&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.query_pairs_mut" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1494-1512">source</a><h4 class="code-header">pub fn <a href="#method.query_pairs_mut" class="fnname">query_pairs_mut</a>(&amp;mut self) -&gt; <a class="struct" href="../form_urlencoded/struct.Serializer.html" title="struct form_urlencoded::Serializer">Serializer</a>&lt;'_, <a class="struct" href="struct.UrlQuery.html" title="struct url::UrlQuery">UrlQuery</a>&lt;'_&gt;&gt;</h4></section></summary><div class="docblock"><p>Manipulate this URL’s query string, viewed as a sequence of name/value pairs
in <code>application/x-www-form-urlencoded</code> syntax.</p>
<p>The return value has a method-chaining API:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.net?lang=fr#nav&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.query(), <span class="prelude-val">Some</span>(<span class="string">&quot;lang=fr&quot;</span>));
url.query_pairs_mut().append_pair(<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar&quot;</span>);
<span class="macro">assert_eq!</span>(url.query(), <span class="prelude-val">Some</span>(<span class="string">&quot;lang=fr&amp;foo=bar&quot;</span>));
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.net/?lang=fr&amp;foo=bar#nav&quot;</span>);
url.query_pairs_mut()
.clear()
.append_pair(<span class="string">&quot;foo&quot;</span>, <span class="string">&quot;bar &amp; baz&quot;</span>)
.append_pair(<span class="string">&quot;saisons&quot;</span>, <span class="string">&quot;\u{00C9}t\u{00E9}+hiver&quot;</span>);
<span class="macro">assert_eq!</span>(url.query(), <span class="prelude-val">Some</span>(<span class="string">&quot;foo=bar+%26+baz&amp;saisons=%C3%89t%C3%A9%2Bhiver&quot;</span>));
<span class="macro">assert_eq!</span>(url.as_str(),
<span class="string">&quot;https://example.net/?foo=bar+%26+baz&amp;saisons=%C3%89t%C3%A9%2Bhiver#nav&quot;</span>);</code></pre></div>
<p>Note: <code>url.query_pairs_mut().clear();</code> is equivalent to <code>url.set_query(Some(&quot;&quot;))</code>,
not <code>url.set_query(None)</code>.</p>
<p>The state of <code>Url</code> is unspecified if this return value is leaked without being dropped.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_path" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1560-1579">source</a><h4 class="code-header">pub fn <a href="#method.set_path" class="fnname">set_path</a>(&amp;mut self, path: &amp;str)</h4></section></summary><div class="docblock"><p>Change this URL’s path.</p>
<h5 id="examples-27"><a href="#examples-27">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
url.set_path(<span class="string">&quot;api/comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/api/comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/api/comments&quot;</span>);
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com/api&quot;</span>)<span class="question-mark">?</span>;
url.set_path(<span class="string">&quot;data/report.csv&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/data/report.csv&quot;</span>);
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/data/report.csv&quot;</span>);
<span class="comment">// `set_path` percent-encodes the given string if it&#39;s not already percent-encoded.
</span><span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
url.set_path(<span class="string">&quot;api/some comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/api/some%20comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/api/some%20comments&quot;</span>);
<span class="comment">// `set_path` will not double percent-encode the string if it&#39;s already percent-encoded.
</span><span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.com&quot;</span>)<span class="question-mark">?</span>;
url.set_path(<span class="string">&quot;api/some%20comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.com/api/some%20comments&quot;</span>);
<span class="macro">assert_eq!</span>(url.path(), <span class="string">&quot;/api/some%20comments&quot;</span>);
</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.path_segments_mut" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1585-1591">source</a><h4 class="code-header">pub fn <a href="#method.path_segments_mut" class="fnname">path_segments_mut</a>(&amp;mut self) -&gt; Result&lt;<a class="struct" href="struct.PathSegmentsMut.html" title="struct url::PathSegmentsMut">PathSegmentsMut</a>&lt;'_&gt;, ()&gt;</h4></section></summary><div class="docblock"><p>Return an object with methods to manipulate this URL’s path segments.</p>
<p>Return <code>Err(())</code> if this URL is cannot-be-a-base.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_port" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1669-1679">source</a><h4 class="code-header">pub fn <a href="#method.set_port" class="fnname">set_port</a>(&amp;mut self, port: Option&lt;u16&gt;) -&gt; Result&lt;(), ()&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s port number.</p>
<p>Note that default port numbers are not reflected in the serialization.</p>
<p>If this URL is cannot-be-a-base, does not have a host, or has the <code>file</code> scheme;
do nothing and return <code>Err</code>.</p>
<h5 id="examples-28"><a href="#examples-28">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;ssh://example.net:2048/&quot;</span>)<span class="question-mark">?</span>;
url.set_port(<span class="prelude-val">Some</span>(<span class="number">4096</span>)).map_err(|<span class="kw">_</span>| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;ssh://example.net:4096/&quot;</span>);
url.set_port(<span class="prelude-val">None</span>).map_err(|<span class="kw">_</span>| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;ssh://example.net/&quot;</span>);</code></pre></div>
<p>Known default port numbers are not reflected:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.org/&quot;</span>)<span class="question-mark">?</span>;
url.set_port(<span class="prelude-val">Some</span>(<span class="number">443</span>)).map_err(|<span class="kw">_</span>| <span class="string">&quot;cannot be base&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert!</span>(url.port().is_none());</code></pre></div>
<p>Cannot set port for cannot-be-a-base URLs:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rms@example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_port(<span class="prelude-val">Some</span>(<span class="number">80</span>));
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span>result = url.set_port(<span class="prelude-val">None</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_host" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1802-1864">source</a><h4 class="code-header">pub fn <a href="#method.set_host" class="fnname">set_host</a>(&amp;mut self, host: Option&lt;&amp;str&gt;) -&gt; Result&lt;(), <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a>&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s host.</p>
<p>Removing the host (calling this with <code>None</code>)
will also remove any username, password, and port number.</p>
<h5 id="examples-29"><a href="#examples-29">Examples</a></h5>
<p>Change host:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_host(<span class="prelude-val">Some</span>(<span class="string">&quot;rust-lang.org&quot;</span>));
<span class="macro">assert!</span>(result.is_ok());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://rust-lang.org/&quot;</span>);</code></pre></div>
<p>Remove host:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;foo://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_host(<span class="prelude-val">None</span>);
<span class="macro">assert!</span>(result.is_ok());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;foo:/&quot;</span>);</code></pre></div>
<p>Cannot remove host for ‘special’ schemes (e.g. <code>http</code>):</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_host(<span class="prelude-val">None</span>);
<span class="macro">assert!</span>(result.is_err());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.net/&quot;</span>);</code></pre></div>
<p>Cannot change or remove host for cannot-be-a-base URLs:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rms@example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_host(<span class="prelude-val">Some</span>(<span class="string">&quot;rust-lang.org&quot;</span>));
<span class="macro">assert!</span>(result.is_err());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;mailto:rms@example.net&quot;</span>);
<span class="kw">let </span>result = url.set_host(<span class="prelude-val">None</span>);
<span class="macro">assert!</span>(result.is_err());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;mailto:rms@example.net&quot;</span>);</code></pre></div>
<h5 id="errors-4"><a href="#errors-4">Errors</a></h5>
<p>If this URL is cannot-be-a-base or there is an error parsing the given <code>host</code>,
a <a href="enum.ParseError.html"><code>ParseError</code></a> variant will be returned.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_ip_host" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1947-1958">source</a><h4 class="code-header">pub fn <a href="#method.set_ip_host" class="fnname">set_ip_host</a>(&amp;mut self, address: IpAddr) -&gt; Result&lt;(), ()&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s host to the given IP address.</p>
<p>If this URL is cannot-be-a-base, do nothing and return <code>Err</code>.</p>
<p>Compared to <code>Url::set_host</code>, this skips the host parser.</p>
<h5 id="examples-30"><a href="#examples-30">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;http://example.com&quot;</span>)<span class="question-mark">?</span>;
url.set_ip_host(<span class="string">&quot;127.0.0.1&quot;</span>.parse().unwrap());
<span class="macro">assert_eq!</span>(url.host_str(), <span class="prelude-val">Some</span>(<span class="string">&quot;127.0.0.1&quot;</span>));
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;http://127.0.0.1/&quot;</span>);</code></pre></div>
<p>Cannot change URL’s from mailto(cannot-be-base) to ip:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rms@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_ip_host(<span class="string">&quot;127.0.0.1&quot;</span>.parse().unwrap());
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;mailto:rms@example.com&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_password" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#1987-2042">source</a><h4 class="code-header">pub fn <a href="#method.set_password" class="fnname">set_password</a>(&amp;mut self, password: Option&lt;&amp;str&gt;) -&gt; Result&lt;(), ()&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s password.</p>
<p>If this URL is cannot-be-a-base or does not have a host, do nothing and return <code>Err</code>.</p>
<h5 id="examples-31"><a href="#examples-31">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rmz@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_password(<span class="prelude-val">Some</span>(<span class="string">&quot;secret_password&quot;</span>));
<span class="macro">assert!</span>(result.is_err());
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;ftp://user1:secret1@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_password(<span class="prelude-val">Some</span>(<span class="string">&quot;secret_password&quot;</span>));
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">Some</span>(<span class="string">&quot;secret_password&quot;</span>));
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;ftp://user2:@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_password(<span class="prelude-val">Some</span>(<span class="string">&quot;secret2&quot;</span>));
<span class="macro">assert!</span>(result.is_ok());
<span class="macro">assert_eq!</span>(url.password(), <span class="prelude-val">Some</span>(<span class="string">&quot;secret2&quot;</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_username" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2080-2129">source</a><h4 class="code-header">pub fn <a href="#method.set_username" class="fnname">set_username</a>(&amp;mut self, username: &amp;str) -&gt; Result&lt;(), ()&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s username.</p>
<p>If this URL is cannot-be-a-base or does not have a host, do nothing and return <code>Err</code>.</p>
<h5 id="examples-32"><a href="#examples-32">Examples</a></h5>
<p>Cannot setup username from mailto(cannot-be-base)</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rmz@example.com&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_username(<span class="string">&quot;user1&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;mailto:rmz@example.com&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
<p>Setup username to user1</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::{Url, ParseError};
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;ftp://:secre1@example.com/&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_username(<span class="string">&quot;user1&quot;</span>);
<span class="macro">assert!</span>(result.is_ok());
<span class="macro">assert_eq!</span>(url.username(), <span class="string">&quot;user1&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;ftp://user1:secre1@example.com/&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.set_scheme" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2242-2291">source</a><h4 class="code-header">pub fn <a href="#method.set_scheme" class="fnname">set_scheme</a>(&amp;mut self, scheme: &amp;str) -&gt; Result&lt;(), ()&gt;</h4></section></summary><div class="docblock"><p>Change this URL’s scheme.</p>
<p>Do nothing and return <code>Err</code> under the following circumstances:</p>
<ul>
<li>If the new scheme is not in <code>[a-zA-Z][a-zA-Z0-9+.-]+</code></li>
<li>If this URL is cannot-be-a-base and the new scheme is one of
<code>http</code>, <code>https</code>, <code>ws</code>, <code>wss</code> or <code>ftp</code></li>
<li>If either the old or new scheme is <code>http</code>, <code>https</code>, <code>ws</code>,
<code>wss</code> or <code>ftp</code> and the other is not one of these</li>
<li>If the new scheme is <code>file</code> and this URL includes credentials
or has a non-null port</li>
<li>If this URL’s scheme is <code>file</code> and its host is empty or null</li>
</ul>
<p>See also <a href="https://url.spec.whatwg.org/#scheme-state">the URL specification’s section on legal scheme state
overrides</a>.</p>
<h5 id="examples-33"><a href="#examples-33">Examples</a></h5>
<p>Change the URL’s scheme from <code>https</code> to <code>http</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;http&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;http://example.net/&quot;</span>);
<span class="macro">assert!</span>(result.is_ok());</code></pre></div>
<p>Change the URL’s scheme from <code>foo</code> to <code>bar</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;foo://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;bar&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;bar://example.net&quot;</span>);
<span class="macro">assert!</span>(result.is_ok());</code></pre></div>
<p>Cannot change URL’s scheme from <code>https</code> to <code>foõ</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;https://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;foõ&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;https://example.net/&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
<p>Cannot change URL’s scheme from <code>mailto</code> (cannot-be-a-base) to <code>https</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;mailto:rms@example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;https&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;mailto:rms@example.net&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
<p>Cannot change the URL’s scheme from <code>foo</code> to <code>https</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;foo://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;https&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;foo://example.net&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
<p>Cannot change the URL’s scheme from <code>http</code> to <code>foo</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span><span class="kw-2">mut </span>url = Url::parse(<span class="string">&quot;http://example.net&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>result = url.set_scheme(<span class="string">&quot;foo&quot;</span>);
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;http://example.net/&quot;</span>);
<span class="macro">assert!</span>(result.is_err());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_file_path" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2322-2338">source</a><h4 class="code-header">pub fn <a href="#method.from_file_path" class="fnname">from_file_path</a>&lt;P:&nbsp;AsRef&lt;Path&gt;&gt;(path: P) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, ()&gt;</h4></section></summary><div class="docblock"><p>Convert a file name as <code>std::path::Path</code> into an URL in the <code>file</code> scheme.</p>
<p>This returns <code>Err</code> if the given path is not absolute or,
on Windows, if the prefix is not a disk prefix (e.g. <code>C:</code>) or a UNC prefix (<code>\\</code>).</p>
<h5 id="examples-34"><a href="#examples-34">Examples</a></h5>
<p>On Unix-like platforms:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>url::Url;
<span class="kw">let </span>url = Url::from_file_path(<span class="string">&quot;/tmp/foo.txt&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(url.as_str(), <span class="string">&quot;file:///tmp/foo.txt&quot;</span>);
<span class="kw">let </span>url = Url::from_file_path(<span class="string">&quot;../foo.txt&quot;</span>);
<span class="macro">assert!</span>(url.is_err());
<span class="kw">let </span>url = Url::from_file_path(<span class="string">&quot;https://google.com/&quot;</span>);
<span class="macro">assert!</span>(url.is_err());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_directory_path" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2359-2365">source</a><h4 class="code-header">pub fn <a href="#method.from_directory_path" class="fnname">from_directory_path</a>&lt;P:&nbsp;AsRef&lt;Path&gt;&gt;(path: P) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, ()&gt;</h4></section></summary><div class="docblock"><p>Convert a directory name as <code>std::path::Path</code> into an URL in the <code>file</code> scheme.</p>
<p>This returns <code>Err</code> if the given path is not absolute or,
on Windows, if the prefix is not a disk prefix (e.g. <code>C:</code>) or a UNC prefix (<code>\\</code>).</p>
<p>Compared to <code>from_file_path</code>, this ensure that URL’s the path has a trailing slash
so that the entire path is considered when using this URL as a base URL.</p>
<p>For example:</p>
<ul>
<li><code>&quot;index.html&quot;</code> parsed with <code>Url::from_directory_path(Path::new(&quot;/var/www&quot;))</code>
as the base URL is <code>file:///var/www/index.html</code></li>
<li><code>&quot;index.html&quot;</code> parsed with <code>Url::from_file_path(Path::new(&quot;/var/www&quot;))</code>
as the base URL is <code>file:///var/index.html</code>, which might not be what was intended.</li>
</ul>
<p>Note that <code>std::path</code> does not consider trailing slashes significant
and usually does not include them (e.g. in <code>Path::parent()</code>).</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.serialize_internal" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2375-2407">source</a><h4 class="code-header">pub fn <a href="#method.serialize_internal" class="fnname">serialize_internal</a>&lt;S&gt;(&amp;self, serializer: S) -&gt; Result&lt;S::<a class="associatedtype" href="../serde/ser/trait.Serializer.html#associatedtype.Ok" title="type serde::ser::Serializer::Ok">Ok</a>, S::<a class="associatedtype" href="../serde/ser/trait.Serializer.html#associatedtype.Error" title="type serde::ser::Serializer::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../serde/ser/trait.Serializer.html" title="trait serde::ser::Serializer">Serializer</a>,</span></h4></section></summary><div class="docblock"><p>Serialize with Serde using the internal representation of the <code>Url</code> struct.</p>
<p>The corresponding <code>deserialize_internal</code> method sacrifices some invariant-checking
for speed, compared to the <code>Deserialize</code> trait impl.</p>
<p>This method is only available if the <code>serde</code> Cargo feature is enabled.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deserialize_internal" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2417-2453">source</a><h4 class="code-header">pub fn <a href="#method.deserialize_internal" class="fnname">deserialize_internal</a>&lt;'de, D&gt;(deserializer: D) -&gt; Result&lt;Self, D::<a class="associatedtype" href="../serde/de/trait.Deserializer.html#associatedtype.Error" title="type serde::de::Deserializer::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../serde/de/trait.Deserializer.html" title="trait serde::de::Deserializer">Deserializer</a>&lt;'de&gt;,</span></h4></section></summary><div class="docblock"><p>Serialize with Serde using the internal representation of the <code>Url</code> struct.</p>
<p>The corresponding <code>deserialize_internal</code> method sacrifices some invariant-checking
for speed, compared to the <code>Deserialize</code> trait impl.</p>
<p>This method is only available if the <code>serde</code> Cargo feature is enabled.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_file_path" class="method has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2476-2489">source</a><h4 class="code-header">pub fn <a href="#method.to_file_path" class="fnname">to_file_path</a>(&amp;self) -&gt; Result&lt;PathBuf, ()&gt;</h4></section></summary><div class="docblock"><p>Assuming the URL is in the <code>file</code> scheme or similar,
convert its path to an absolute <code>std::path::Path</code>.</p>
<p><strong>Note:</strong> This does not actually check the URL’s <code>scheme</code>,
and may give nonsensical results for other schemes.
It is the user’s responsibility to check the URL’s scheme before calling this.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>path = url.to_file_path();</code></pre></div>
<p>Returns <code>Err</code> if the host is neither empty nor <code>&quot;localhost&quot;</code> (except on Windows, where
<code>file:</code> URLs may have a non-local host),
or if <code>Path::new_opt()</code> returns <code>None</code>.
(That is, if the percent-decoded path contains a NUL byte or,
for a Windows path, is not UTF-8.)</p>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3Cstr%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2598-2603">source</a><a href="#impl-AsRef%3Cstr%3E-for-Url" class="anchor"></a><h3 class="code-header">impl AsRef&lt;str&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Return the serialization of this URL.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2600-2602">source</a><a href="#method.as_ref" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;str</h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Clone-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#169">source</a><a href="#impl-Clone-for-Url" class="anchor"></a><h3 class="code-header">impl Clone for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#169">source</a><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone</a>(&amp;self) -&gt; <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h4></section></summary><div class='docblock'>Returns a copy of the value. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clone_from</a>(&amp;mut self, source: &amp;Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2541-2557">source</a><a href="#impl-Debug-for-Url" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Debug the serialization of this URL.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2543-2556">source</a><a href="#method.fmt-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Deserialize%3C%27de%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2647-2676">source</a><a href="#impl-Deserialize%3C%27de%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;'de&gt; <a class="trait" href="../serde/de/trait.Deserialize.html" title="trait serde::de::Deserialize">Deserialize</a>&lt;'de&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Deserializes this URL from a <code>serde</code> stream.</p>
<p>This implementation is only available if the <code>serde</code> Cargo feature is enabled.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.deserialize" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2648-2675">source</a><a href="#method.deserialize" class="anchor"></a><h4 class="code-header">fn <a href="../serde/de/trait.Deserialize.html#tymethod.deserialize" class="fnname">deserialize</a>&lt;D&gt;(deserializer: D) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, D::<a class="associatedtype" href="../serde/de/trait.Deserializer.html#associatedtype.Error" title="type serde::de::Deserializer::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="../serde/de/trait.Deserializer.html" title="trait serde::de::Deserializer">Deserializer</a>&lt;'de&gt;,</span></h4></section></summary><div class='docblock'>Deserialize this value from the given Serde deserializer. <a href="../serde/de/trait.Deserialize.html#tymethod.deserialize">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Display-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2526-2531">source</a><a href="#impl-Display-for-Url" class="anchor"></a><h3 class="code-header">impl Display for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Display the serialization of this URL.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2528-2530">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, formatter: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-From%3CUrl%3E-for-String" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2534-2538">source</a><a href="#impl-From%3CUrl%3E-for-String" class="anchor"></a><h3 class="code-header">impl From&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>&gt; for String</h3></section></summary><div class="docblock"><p>String conversion.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2535-2537">source</a><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(value: <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>) -&gt; String</h4></section></summary><div class='docblock'>Converts to this type from the input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-FromStr-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2508-2515">source</a><a href="#impl-FromStr-for-Url" class="anchor"></a><h3 class="code-header">impl FromStr for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Parse a string as an URL, without a base URL or encoding override.</p>
</div><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Err" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Err" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Err</a> = <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a></h4></section></summary><div class='docblock'>The associated error which can be returned from parsing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_str" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2512-2514">source</a><a href="#method.from_str" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from_str</a>(input: &amp;str) -&gt; Result&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>, <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a>&gt;</h4></section></summary><div class='docblock'>Parses a string <code>s</code> to return a value of this type. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Hash-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2587-2595">source</a><a href="#impl-Hash-for-Url" class="anchor"></a><h3 class="code-header">impl Hash for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>URLs hash like their serialization.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2589-2594">source</a><a href="#method.hash" class="anchor"></a><h4 class="code-header">fn <a class="fnname">hash</a>&lt;H&gt;(&amp;self, state: &amp;mut H)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Hasher,</span></h4></section></summary><div class='docblock'>Feeds this value into the given [<code>Hasher</code>]. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.hash_slice" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.3.0">1.3.0</span><a href="#method.hash_slice" class="anchor"></a><h4 class="code-header">fn <a class="fnname">hash_slice</a>&lt;H&gt;(data: &amp;[Self], state: &amp;mut H)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;H: Hasher,</span></h4></section></summary><div class='docblock'>Feeds a slice of this type into the given [<code>Hasher</code>]. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Index%3CRange%3CPosition%3E%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#33-38">source</a><a href="#impl-Index%3CRange%3CPosition%3E%3E-for-Url" class="anchor"></a><h3 class="code-header">impl Index&lt;Range&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-3" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-3" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = str</h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.index-3" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#35-37">source</a><a href="#method.index-3" class="anchor"></a><h4 class="code-header">fn <a class="fnname">index</a>(&amp;self, range: Range&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;) -&gt; &amp;str</h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeFrom%3CPosition%3E%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#19-24">source</a><a href="#impl-Index%3CRangeFrom%3CPosition%3E%3E-for-Url" class="anchor"></a><h3 class="code-header">impl Index&lt;RangeFrom&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = str</h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.index-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#21-23">source</a><a href="#method.index-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">index</a>(&amp;self, range: RangeFrom&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;) -&gt; &amp;str</h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeFull%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#12-17">source</a><a href="#impl-Index%3CRangeFull%3E-for-Url" class="anchor"></a><h3 class="code-header">impl Index&lt;RangeFull&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = str</h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.index" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#14-16">source</a><a href="#method.index" class="anchor"></a><h4 class="code-header">fn <a class="fnname">index</a>(&amp;self, _: RangeFull) -&gt; &amp;str</h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Index%3CRangeTo%3CPosition%3E%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#26-31">source</a><a href="#impl-Index%3CRangeTo%3CPosition%3E%3E-for-Url" class="anchor"></a><h3 class="code-header">impl Index&lt;RangeTo&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Output-2" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Output-2" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Output</a> = str</h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.index-2" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/slicing.rs.html#28-30">source</a><a href="#method.index-2" class="anchor"></a><h4 class="code-header">fn <a class="fnname">index</a>(&amp;self, range: RangeTo&lt;<a class="enum" href="enum.Position.html" title="enum url::Position">Position</a>&gt;) -&gt; &amp;str</h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Ord-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2571-2576">source</a><a href="#impl-Ord-for-Url" class="anchor"></a><h3 class="code-header">impl Ord for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>URLs compare like their serialization.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.cmp" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2573-2575">source</a><a href="#method.cmp" class="anchor"></a><h4 class="code-header">fn <a class="fnname">cmp</a>(&amp;self, other: &amp;Self) -&gt; Ordering</h4></section></summary><div class='docblock'>This method returns an [<code>Ordering</code>] between <code>self</code> and <code>other</code>. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.max" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.21.0">1.21.0</span><a href="#method.max" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">max</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'>Compares and returns the maximum of two values. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.min" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.21.0">1.21.0</span><a href="#method.min" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">min</a>(self, other: Self) -&gt; Self</h4></section></summary><div class='docblock'>Compares and returns the minimum of two values. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clamp" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.50.0">1.50.0</span><a href="#method.clamp" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clamp</a>(self, min: Self, max: Self) -&gt; Self<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: PartialOrd&lt;Self&gt;,</span></h4></section></summary><div class='docblock'>Restrict a value to a certain interval. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialEq%3CUrl%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2563-2568">source</a><a href="#impl-PartialEq%3CUrl%3E-for-Url" class="anchor"></a><h3 class="code-header">impl PartialEq&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>URLs compare like their serialization.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.eq" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2565-2567">source</a><a href="#method.eq" class="anchor"></a><h4 class="code-header">fn <a class="fnname">eq</a>(&amp;self, other: &amp;Self) -&gt; bool</h4></section></summary><div class='docblock'>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
by <code>==</code>. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ne" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.ne" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">ne</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests for <code>!=</code>. The default implementation is almost always
sufficient, and should not be overridden without very good reason. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-PartialOrd%3CUrl%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2579-2584">source</a><a href="#impl-PartialOrd%3CUrl%3E-for-Url" class="anchor"></a><h3 class="code-header">impl PartialOrd&lt;<a class="struct" href="struct.Url.html" title="struct url::Url">Url</a>&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>URLs compare like their serialization.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.partial_cmp" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2581-2583">source</a><a href="#method.partial_cmp" class="anchor"></a><h4 class="code-header">fn <a class="fnname">partial_cmp</a>(&amp;self, other: &amp;Self) -&gt; Option&lt;Ordering&gt;</h4></section></summary><div class='docblock'>This method returns an ordering between <code>self</code> and <code>other</code> values if one exists. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lt" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.lt" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">lt</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests less than (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;</code> operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.le" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.le" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">le</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests less than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&lt;=</code>
operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.gt" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.gt" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">gt</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests greater than (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;</code> operator. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ge" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.ge" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">ge</a>(&amp;self, other: &amp;Rhs) -&gt; bool</h4></section></summary><div class='docblock'>This method tests greater than or equal to (for <code>self</code> and <code>other</code>) and is used by the <code>&gt;=</code>
operator. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Serialize-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2634-2641">source</a><a href="#impl-Serialize-for-Url" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../serde/ser/trait.Serialize.html" title="trait serde::ser::Serialize">Serialize</a> for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="docblock"><p>Serializes this URL into a <code>serde</code> stream.</p>
<p>This implementation is only available if the <code>serde</code> Cargo feature is enabled.</p>
</div><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.serialize" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2635-2640">source</a><a href="#method.serialize" class="anchor"></a><h4 class="code-header">fn <a href="../serde/ser/trait.Serialize.html#tymethod.serialize" class="fnname">serialize</a>&lt;S&gt;(&amp;self, serializer: S) -&gt; Result&lt;S::<a class="associatedtype" href="../serde/ser/trait.Serializer.html#associatedtype.Ok" title="type serde::ser::Serializer::Ok">Ok</a>, S::<a class="associatedtype" href="../serde/ser/trait.Serializer.html#associatedtype.Error" title="type serde::ser::Serializer::Error">Error</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../serde/ser/trait.Serializer.html" title="trait serde::ser::Serializer">Serializer</a>,</span></h4></section></summary><div class='docblock'>Serialize this value into the given Serde serializer. <a href="../serde/ser/trait.Serialize.html#tymethod.serialize">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-TryFrom%3C%26%27a%20str%3E-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2517-2523">source</a><a href="#impl-TryFrom%3C%26%27a%20str%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;'a&gt; TryFrom&lt;&amp;'a str&gt; for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = <a class="enum" href="enum.ParseError.html" title="enum url::ParseError">ParseError</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2520-2522">source</a><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(s: &amp;'a str) -&gt; Result&lt;Self, Self::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><section id="impl-Eq-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/url/lib.rs.html#2560">source</a><a href="#impl-Eq-for-Url" class="anchor"></a><h3 class="code-header">impl Eq for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section><div class="docblock"><p>URLs compare like their serialization.</p>
</div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-Url" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-Url" class="anchor"></a><h3 class="code-header">impl RefUnwindSafe for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section><section id="impl-Send-for-Url" class="impl has-srclink"><a href="#impl-Send-for-Url" class="anchor"></a><h3 class="code-header">impl Send for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section><section id="impl-Sync-for-Url" class="impl has-srclink"><a href="#impl-Sync-for-Url" class="anchor"></a><h3 class="code-header">impl Sync for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section><section id="impl-Unpin-for-Url" class="impl has-srclink"><a href="#impl-Unpin-for-Url" class="anchor"></a><h3 class="code-header">impl Unpin for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section><section id="impl-UnwindSafe-for-Url" class="impl has-srclink"><a href="#impl-UnwindSafe-for-Url" class="anchor"></a><h3 class="code-header">impl UnwindSafe for <a class="struct" href="struct.Url.html" title="struct url::Url">Url</a></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-Url" class="impl has-srclink"><a href="#impl-Any-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-Url" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-Url" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-Url" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from-1" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-Url" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToOwned-for-Url" class="impl has-srclink"><a href="#impl-ToOwned-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; ToOwned for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Clone,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl has-srclink"><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a class="fnname">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl has-srclink"><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone_into</a>(&amp;self, target: &amp;mut T)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToString-for-Url" class="impl has-srclink"><a href="#impl-ToString-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; ToString for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Display + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_string" class="method trait-impl has-srclink"><a href="#method.to_string" class="anchor"></a><h4 class="code-header">default fn <a class="fnname">to_string</a>(&amp;self) -&gt; String</h4></section></summary><div class='docblock'>Converts the given value to a <code>String</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-Url" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-2" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-2" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from-1" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-Url" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><section id="impl-DeserializeOwned-for-Url" class="impl has-srclink"><a class="srclink rightside" href="../src/serde/de/mod.rs.html#604">source</a><a href="#impl-DeserializeOwned-for-Url" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="../serde/de/trait.DeserializeOwned.html" title="trait serde::de::DeserializeOwned">DeserializeOwned</a> for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: for&lt;'de&gt; <a class="trait" href="../serde/de/trait.Deserialize.html" title="trait serde::de::Deserialize">Deserialize</a>&lt;'de&gt;,</span></h3></section></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="url" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>