edlang/percent_encoding/index.html

26 lines
9.4 KiB
HTML
Raw Normal View History

<!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="URLs use special characters to indicate the parts of the request. For example, a `?` 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."><title>percent_encoding - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-5bc39a1768837dd0.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="percent_encoding" data-themes="" data-resource-suffix="" data-rustdoc-version="1.77.1 (7cf61ebde 2024-03-27)" data-channel="1.77.1" data-search-js="search-dd67cee4cfa65049.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-4c98445ec4002617.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-48f368f3872407c8.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-04d5337699b92874.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[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" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../percent_encoding/index.html">percent_encoding</a><span class="version">2.3.1</span></h2></div><div class="sidebar-elems"><ul class="block">
<li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../percent_encoding/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">percent_encoding</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/percent_encoding/lib.rs.html#9-477">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>URLs use special characters 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="struct.AsciiSet.html" title="struct percent_encoding::AsciiSet"><code>AsciiSet</code></a> parameter of <a href="fn.percent_encode.html" title="fn percent_encoding::percent_encode"><code>percent_encode</code></a> and <a href="fn.utf8_percent_encode.html" title="fn percent_encoding::utf8_percent_encode"><code>utf8_percent_encode</code></a>
lets callers configure this.</p>
<p>This crate deliberately does not provide many different sets.
Users should consider in what context the encoded string will be used,
read relevant specifications, and define their own set.
This is done by using the <code>add</code> method of an existing set.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
<span class="doccomment">/// https://url.spec.whatwg.org/#fragment-percent-encode-set
</span><span class="kw">const </span>FRAGMENT: <span class="kw-2">&amp;</span>AsciiSet = <span class="kw-2">&amp;</span>CONTROLS.add(<span class="string">b' '</span>).add(<span class="string">b'"'</span>).add(<span class="string">b'&lt;'</span>).add(<span class="string">b'&gt;'</span>).add(<span class="string">b'`'</span>);
<span class="macro">assert_eq!</span>(utf8_percent_encode(<span class="string">"foo &lt;bar&gt;"</span>, FRAGMENT).to_string(), <span class="string">"foo%20%3Cbar%3E"</span>);</code></pre></div>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.AsciiSet.html" title="struct percent_encoding::AsciiSet">AsciiSet</a></div><div class="desc docblock-short">Represents a set of characters or bytes in the ASCII range.</div></li><li><div class="item-name"><a class="struct" href="struct.PercentDecode.html" title="struct percent_encoding::PercentDecode">PercentDecode</a></div><div class="desc docblock-short">The return type of <a href="fn.percent_decode.html" title="fn percent_encoding::percent_decode"><code>percent_decode</code></a>.</div></li><li><div class="item-name"><a class="struct" href="struct.PercentEncode.html" title="struct percent_encoding::PercentEncode">PercentEncode</a></div><div class="desc docblock-short">The return type of <a href="fn.percent_encode.html" title="fn percent_encoding::percent_encode"><code>percent_encode</code></a> and <a href="fn.utf8_percent_encode.html" title="fn percent_encoding::utf8_percent_encode"><code>utf8_percent_encode</code></a>.</div></li></ul><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.CONTROLS.html" title="constant percent_encoding::CONTROLS">CONTROLS</a></div><div class="desc docblock-short">The set of 0x00 to 0x1F (C0 controls), and 0x7F (DEL).</div></li><li><div class="item-name"><a class="constant" href="constant.NON_ALPHANUMERIC.html" title="constant percent_encoding::NON_ALPHANUMERIC">NON_ALPHANUMERIC</a></div><div class="desc docblock-short">Everything that is not an ASCII letter or digit.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.percent_decode.html" title="fn percent_encoding::percent_decode">percent_decode</a></div><div class="desc docblock-short">Percent-decode the given bytes.</div></li><li><div class="item-name"><a class="fn" href="fn.percent_decode_str.html" title="fn percent_encoding::percent_decode_str">percent_decode_str</a></div><div class="desc docblock-short">Percent-decode the given string.</div></li><li><div class="item-name"><a class="fn" href="fn.percent_encode.html" title="fn percent_encoding::percent_encode">percent_encode</a></div><div class="desc docblock-short">Percent-encode the given bytes with the given set.</div></li><li><div class="item-name"><a class="fn" href="fn.percent_encode_byte.html" title="fn percent_encoding::percent_encode_byte">percent_encode_byte</a></div><div class="desc docblock-short">Return the percent-encoding of the given byte.</div></li><li><div class="item-name"><a class="fn" href="fn.utf8_percent_encode.html" title="fn percent_encoding::utf8_percent_encode">utf8_percent_encode</a></div><div class="desc docblock-short">Percent-encode the UTF-8 encoding of the given string.</div></li></ul></section></div></main></body></html>