Files
rapr-rs/docs/url/index.html
T
2021-03-14 20:06:11 +00:00

91 lines
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!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="API documentation for the Rust `url` crate."><meta name="keywords" content="rust, rustlang, rust-lang, url"><title>url - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../url/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate url</p><div class="block version"><p>Version 2.2.1</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all url's items</p></a><div class="block items"><ul><li><a href="#reexports">Re-exports</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#types">Type Definitions</a></li></ul></div><p class="location"></p><script>window.sidebarCurrent = {name: "url", ty: "mod", relpath: "../"};</script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"></div><button type="button" class="help-button">?</button>
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span><a class="srclink" href="../src/url/lib.rs.html#9-2745" title="goto source code">[src]</a></span><span class="in-band">Crate <a class="mod" href="">url</a></span></h1><div class="docblock"><p>rust-url is an implementation of the <a href="http://url.spec.whatwg.org/">URL Standard</a>
for the <a href="http://rust-lang.org/">Rust</a> programming language.</p>
<h1 id="url-parsing-and-data-structures" class="section-header"><a href="#url-parsing-and-data-structures">URL parsing and data structures</a></h1>
<p>First, URL parsing may fail for various reasons and therefore returns a <code>Result</code>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">url</span>::{<span class="ident">Url</span>, <span class="ident">ParseError</span>};
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">Url</span>::<span class="ident">parse</span>(<span class="string">&quot;http://[:::1]&quot;</span>) <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Err</span>(<span class="ident">ParseError</span>::<span class="ident">InvalidIpv6Address</span>))</pre></div>
<p>Lets parse a valid URL and look at its components.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">url</span>::{<span class="ident">Url</span>, <span class="ident">Host</span>, <span class="ident">Position</span>};
<span class="kw">let</span> <span class="ident">issue_list_url</span> <span class="op">=</span> <span class="ident">Url</span>::<span class="ident">parse</span>(
<span class="string">&quot;https://github.com/rust-lang/rust/issues?labels=E-easy&amp;state=open&quot;</span>
)<span class="question-mark">?</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">scheme</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&quot;https&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">username</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&quot;&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">password</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">None</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">host_str</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">&quot;github.com&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">host</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">Host</span>::<span class="ident">Domain</span>(<span class="string">&quot;github.com&quot;</span>)));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">port</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">None</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">path</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&quot;/rust-lang/rust/issues&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">path_segments</span>().<span class="ident">map</span>(<span class="op">|</span><span class="ident">c</span><span class="op">|</span> <span class="ident">c</span>.<span class="ident">collect</span>::<span class="op">&lt;</span><span class="ident">Vec</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span><span class="op">&gt;</span>()) <span class="op">=</span><span class="op">=</span>
<span class="prelude-val">Some</span>(<span class="macro">vec</span><span class="macro">!</span>[<span class="string">&quot;rust-lang&quot;</span>, <span class="string">&quot;rust&quot;</span>, <span class="string">&quot;issues&quot;</span>]));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">query</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">&quot;labels=E-easy&amp;state=open&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="kw-2">&amp;</span><span class="ident">issue_list_url</span>[<span class="ident">Position</span>::<span class="ident">BeforePath</span>..] <span class="op">=</span><span class="op">=</span> <span class="string">&quot;/rust-lang/rust/issues?labels=E-easy&amp;state=open&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">issue_list_url</span>.<span class="ident">fragment</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">None</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">issue_list_url</span>.<span class="ident">cannot_be_a_base</span>());</pre></div>
<p>Some URLs are said to be <em>cannot-be-a-base</em>:
they dont have a username, password, host, or port,
and their &quot;path&quot; is an arbitrary string rather than slash-separated segments:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">url</span>::<span class="ident">Url</span>;
<span class="kw">let</span> <span class="ident">data_url</span> <span class="op">=</span> <span class="ident">Url</span>::<span class="ident">parse</span>(<span class="string">&quot;data:text/plain,Hello?World#&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">cannot_be_a_base</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">scheme</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&quot;data&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">path</span>() <span class="op">=</span><span class="op">=</span> <span class="string">&quot;text/plain,Hello&quot;</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">path_segments</span>().<span class="ident">is_none</span>());
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">query</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">&quot;World&quot;</span>));
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">data_url</span>.<span class="ident">fragment</span>() <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Some</span>(<span class="string">&quot;&quot;</span>));</pre></div>
<h2 id="serde" class="section-header"><a href="#serde">Serde</a></h2>
<p>Enable the <code>serde</code> feature to include <code>Deserialize</code> and <code>Serialize</code> implementations for <code>url::Url</code>.</p>
<h1 id="base-url" class="section-header"><a href="#base-url">Base URL</a></h1>
<p>Many contexts allow URL <em>references</em> that can be relative to a <em>base URL</em>:</p>
<pre><code class="language-html">&lt;link rel=&quot;stylesheet&quot; href=&quot;../main.css&quot;&gt;
</code></pre>
<p>Since parsed URLs are absolute, giving a base is required for parsing relative URLs:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">url</span>::{<span class="ident">Url</span>, <span class="ident">ParseError</span>};
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">Url</span>::<span class="ident">parse</span>(<span class="string">&quot;../main.css&quot;</span>) <span class="op">=</span><span class="op">=</span> <span class="prelude-val">Err</span>(<span class="ident">ParseError</span>::<span class="ident">RelativeUrlWithoutBase</span>))</pre></div>
<p>Use the <code>join</code> method on an <code>Url</code> to use it as a base URL:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">url</span>::<span class="ident">Url</span>;
<span class="kw">let</span> <span class="ident">this_document</span> <span class="op">=</span> <span class="ident">Url</span>::<span class="ident">parse</span>(<span class="string">&quot;http://servo.github.io/rust-url/url/index.html&quot;</span>)<span class="question-mark">?</span>;
<span class="kw">let</span> <span class="ident">css_url</span> <span class="op">=</span> <span class="ident">this_document</span>.<span class="ident">join</span>(<span class="string">&quot;../main.css&quot;</span>)<span class="question-mark">?</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">css_url</span>.<span class="ident">as_str</span>(), <span class="string">&quot;http://servo.github.io/rust-url/main.css&quot;</span>);</pre></div>
<h1 id="feature-serde" class="section-header"><a href="#feature-serde">Feature: <code>serde</code></a></h1>
<p>If you enable the <code>serde</code> feature, <a href="struct.Url.html"><code>Url</code></a> will implement
<a href="https://docs.rs/serde/1/serde/trait.Serialize.html"><code>serde::Serialize</code></a> and
<a href="https://docs.rs/serde/1/serde/trait.Deserialize.html"><code>serde::Deserialize</code></a>.
See <a href="https://serde.rs">serde documentation</a> for more information.</p>
<pre><code class="language-toml">url = { version = &quot;2&quot;, features = [&quot;serde&quot;] }
</code></pre>
</div><h2 id="reexports" class="section-header"><a href="#reexports">Re-exports</a></h2>
<table><tr><td><code>pub use <a class="mod" href="../form_urlencoded/index.html" title="mod form_urlencoded">form_urlencoded</a>;</code></td></tr></table><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
<table><tr class="module-item"><td><a class="struct" href="struct.OpaqueOrigin.html" title="url::OpaqueOrigin struct">OpaqueOrigin</a></td><td class="docblock-short"><p>Opaque identifier for URLs that have file or other schemes</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.ParseOptions.html" title="url::ParseOptions struct">ParseOptions</a></td><td class="docblock-short"><p>Full configuration for the URL parser.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.PathSegmentsMut.html" title="url::PathSegmentsMut struct">PathSegmentsMut</a></td><td class="docblock-short"><p>Exposes methods to manipulate the path of an URL that is not cannot-be-base.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.Url.html" title="url::Url struct">Url</a></td><td class="docblock-short"><p>A parsed URL record.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.UrlQuery.html" title="url::UrlQuery struct">UrlQuery</a></td><td class="docblock-short"><p>Implementation detail of <code>Url::query_pairs_mut</code>. Typically not used directly.</p>
</td></tr></table><h2 id="enums" class="section-header"><a href="#enums">Enums</a></h2>
<table><tr class="module-item"><td><a class="enum" href="enum.Host.html" title="url::Host enum">Host</a></td><td class="docblock-short"><p>The host name of an URL.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.Origin.html" title="url::Origin enum">Origin</a></td><td class="docblock-short"><p>The origin of an URL</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.ParseError.html" title="url::ParseError enum">ParseError</a></td><td class="docblock-short"><p>Errors that can occur during parsing.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.Position.html" title="url::Position enum">Position</a></td><td class="docblock-short"><p>Indicates a position within a URL based on its components.</p>
</td></tr><tr class="module-item"><td><a class="enum" href="enum.SyntaxViolation.html" title="url::SyntaxViolation enum">SyntaxViolation</a></td><td class="docblock-short"><p>Non-fatal syntax violations that can occur during parsing.</p>
</td></tr></table><h2 id="types" class="section-header"><a href="#types">Type Definitions</a></h2>
<table><tr class="module-item"><td><a class="type" href="type.EncodingOverride.html" title="url::EncodingOverride type">EncodingOverride</a></td><td class="docblock-short"></td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><script>window.rootPath = "../";window.currentCrate = "url";</script><script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>