23 lines
8.1 KiB
HTML
23 lines
8.1 KiB
HTML
<!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-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.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.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">Crate percent_encoding</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../percent_encoding/index.html">percent_<wbr>encoding</a><span class="version">2.3.2</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#constants" title="Constants">Constants</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>percent_<wbr>encoding</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/percent_encoding/lib.rs.html#9-481">Source</a> </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">&</span>AsciiSet = <span class="kw-2">&</span>CONTROLS.add(<span class="string">b' '</span>).add(<span class="string">b'"'</span>).add(<span class="string">b'<'</span>).add(<span class="string">b'>'</span>).add(<span class="string">b'`'</span>);
|
||
|
||
<span class="macro">assert_eq!</span>(utf8_percent_encode(<span class="string">"foo <bar>"</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><dl class="item-table"><dt><a class="struct" href="struct.AsciiSet.html" title="struct percent_encoding::AsciiSet">Ascii<wbr>Set</a></dt><dd>Represents a set of characters or bytes in the ASCII range.</dd><dt><a class="struct" href="struct.PercentDecode.html" title="struct percent_encoding::PercentDecode">Percent<wbr>Decode</a></dt><dd>The return type of <a href="fn.percent_decode.html" title="fn percent_encoding::percent_decode"><code>percent_decode</code></a>.</dd><dt><a class="struct" href="struct.PercentEncode.html" title="struct percent_encoding::PercentEncode">Percent<wbr>Encode</a></dt><dd>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>.</dd></dl><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><dl class="item-table"><dt><a class="constant" href="constant.CONTROLS.html" title="constant percent_encoding::CONTROLS">CONTROLS</a></dt><dd>The set of 0x00 to 0x1F (C0 controls), and 0x7F (DEL).</dd><dt><a class="constant" href="constant.NON_ALPHANUMERIC.html" title="constant percent_encoding::NON_ALPHANUMERIC">NON_<wbr>ALPHANUMERIC</a></dt><dd>Everything that is not an ASCII letter or digit.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.percent_decode.html" title="fn percent_encoding::percent_decode">percent_<wbr>decode</a></dt><dd>Percent-decode the given bytes.</dd><dt><a class="fn" href="fn.percent_decode_str.html" title="fn percent_encoding::percent_decode_str">percent_<wbr>decode_<wbr>str</a></dt><dd>Percent-decode the given string.</dd><dt><a class="fn" href="fn.percent_encode.html" title="fn percent_encoding::percent_encode">percent_<wbr>encode</a></dt><dd>Percent-encode the given bytes with the given set.</dd><dt><a class="fn" href="fn.percent_encode_byte.html" title="fn percent_encoding::percent_encode_byte">percent_<wbr>encode_<wbr>byte</a></dt><dd>Return the percent-encoding of the given byte.</dd><dt><a class="fn" href="fn.utf8_percent_encode.html" title="fn percent_encoding::utf8_percent_encode">utf8_<wbr>percent_<wbr>encode</a></dt><dd>Percent-encode the UTF-8 encoding of the given string.</dd></dl></section></div></main></body></html> |