edlang/percent_encoding/index.html
2024-07-26 09:42:18 +00:00

24 lines
8.4 KiB
HTML
Raw Permalink 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.

<!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><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-dd39b87e5fcfba68.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.80.0 (051478957 2024-07-21)" data-channel="1.80.0" data-search-js="search-d52510db62a78183.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-118b08c4c78b968e.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-20a3ad099b048cf2.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-df360f571f6edeae.css"></noscript><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"><rustdoc-search></rustdoc-search><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">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>