Files
google-apis-rs/percent_encoding/index.html
2021-04-02 00:20:57 +08:00

42 lines
9.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 `percent_encoding` crate."><meta name="keywords" content="rust, rustlang, rust-lang, percent_encoding"><title>percent_encoding - 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='../percent_encoding/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Crate percent_encoding</p><div class="block version"><p>Version 2.1.0</p></div><div class="sidebar-elems"><a id="all-types" href="all.html"><p>See all percent_encoding's items</p></a><div class="block items"><ul><li><a href="#structs">Structs</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></div><p class="location"></p><div id="sidebar-vars" data-name="percent_encoding" data-ty="mod" data-relpath="../"></div></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="in-band">Crate <a class="mod" href="">percent_encoding</a></span><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/percent_encoding/lib.rs.html#9-442" title="goto source code">[src]</a></span></h1><div class="docblock"><p>URLs use special chacters to indicate the parts of the request.
For example, a <code>?</code> question mark marks the end of a path and the start of a query string.
In order for that character to exist inside a path, it needs to be encoded differently.</p>
<p>Percent encoding replaces reserved characters with the <code>%</code> escape character
followed by a byte value as two hexadecimal digits.
For example, an ASCII space is replaced with <code>%20</code>.</p>
<p>When encoding, the set of characters that can (and should, for readability) be left alone
depends on the context.
The <code>?</code> question mark mentioned above is not a separator when used literally
inside of a query string, and therefore does not need to be encoded.
The <a href="../percent_encoding/struct.AsciiSet.html" title="AsciiSet"><code>AsciiSet</code></a> parameter of <a href="../percent_encoding/fn.percent_encode.html" title="percent_encode"><code>percent_encode</code></a> and <a href="../percent_encoding/fn.utf8_percent_encode.html" title="utf8_percent_encode"><code>utf8_percent_encode</code></a>
lets callers configure this.</p>
<p>This crate delibarately does not provide many different sets.
Users should consider in what context the encoded string will be used,
real relevant specifications, and define their own set.
This is done by using the <code>add</code> method of an existing set.</p>
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">percent_encoding</span>::{<span class="ident">utf8_percent_encode</span>, <span class="ident">AsciiSet</span>, <span class="ident">CONTROLS</span>};
<span class="doccomment">/// https://url.spec.whatwg.org/#fragment-percent-encode-set</span>
<span class="kw">const</span> <span class="ident">FRAGMENT</span>: <span class="kw-2">&amp;</span><span class="ident">AsciiSet</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">CONTROLS</span>.<span class="ident">add</span>(<span class="string">b&#39; &#39;</span>).<span class="ident">add</span>(<span class="string">b&#39;&quot;&#39;</span>).<span class="ident">add</span>(<span class="string">b&#39;&lt;&#39;</span>).<span class="ident">add</span>(<span class="string">b&#39;&gt;&#39;</span>).<span class="ident">add</span>(<span class="string">b&#39;`&#39;</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">utf8_percent_encode</span>(<span class="string">&quot;foo &lt;bar&gt;&quot;</span>, <span class="ident">FRAGMENT</span>).<span class="ident">to_string</span>(), <span class="string">&quot;foo%20%3Cbar%3E&quot;</span>);</pre></div>
</div><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
<table><tr class="module-item"><td><a class="struct" href="struct.AsciiSet.html" title="percent_encoding::AsciiSet struct">AsciiSet</a></td><td class="docblock-short"><p>Represents a set of characters or bytes in the ASCII range.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.PercentDecode.html" title="percent_encoding::PercentDecode struct">PercentDecode</a></td><td class="docblock-short"><p>The return type of <a href="../percent_encoding/fn.percent_decode.html" title="percent_decode"><code>percent_decode</code></a>.</p>
</td></tr><tr class="module-item"><td><a class="struct" href="struct.PercentEncode.html" title="percent_encoding::PercentEncode struct">PercentEncode</a></td><td class="docblock-short"><p>The return type of <a href="../percent_encoding/fn.percent_encode.html" title="percent_encode"><code>percent_encode</code></a> and <a href="../percent_encoding/fn.utf8_percent_encode.html" title="utf8_percent_encode"><code>utf8_percent_encode</code></a>.</p>
</td></tr></table><h2 id="constants" class="section-header"><a href="#constants">Constants</a></h2>
<table><tr class="module-item"><td><a class="constant" href="constant.CONTROLS.html" title="percent_encoding::CONTROLS constant">CONTROLS</a></td><td class="docblock-short"><p>The set of 0x00 to 0x1F (C0 controls), and 0x7F (DEL).</p>
</td></tr><tr class="module-item"><td><a class="constant" href="constant.NON_ALPHANUMERIC.html" title="percent_encoding::NON_ALPHANUMERIC constant">NON_ALPHANUMERIC</a></td><td class="docblock-short"><p>Everything that is not an ASCII letter or digit.</p>
</td></tr></table><h2 id="functions" class="section-header"><a href="#functions">Functions</a></h2>
<table><tr class="module-item"><td><a class="fn" href="fn.percent_decode.html" title="percent_encoding::percent_decode fn">percent_decode</a></td><td class="docblock-short"><p>Percent-decode the given bytes.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.percent_decode_str.html" title="percent_encoding::percent_decode_str fn">percent_decode_str</a></td><td class="docblock-short"><p>Percent-decode the given string.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.percent_encode.html" title="percent_encoding::percent_encode fn">percent_encode</a></td><td class="docblock-short"><p>Percent-encode the given bytes with the given set.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.percent_encode_byte.html" title="percent_encoding::percent_encode_byte fn">percent_encode_byte</a></td><td class="docblock-short"><p>Return the percent-encoding of the given byte.</p>
</td></tr><tr class="module-item"><td><a class="fn" href="fn.utf8_percent_encode.html" title="percent_encoding::utf8_percent_encode fn">utf8_percent_encode</a></td><td class="docblock-short"><p>Percent-encode the UTF-8 encoding of the given string.</p>
</td></tr></table></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="percent_encoding"></div>
<script src="../main.js"></script><script defer src="../search-index.js"></script></body></html>