blob: b666e2b1778b3731b0a783d211fdbf87a7de2ccf [file] [log] [blame]
<!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="Configs"><meta name="keywords" content="rust, rustlang, rust-lang, base64"><title>base64 - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.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">&#9776;</button><a class="sidebar-logo" href="../base64/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../base64/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate base64</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.13.1</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li><li><a href="#enums">Enums</a></li><li><a href="#constants">Constants</a></li><li><a href="#functions">Functions</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Crate <a class="mod" href="#">base64</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/base64/lib.rs.html#1-245">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="configs"><a href="#configs">Configs</a></h2>
<p>There isn’t just one type of Base64; that would be too simple. You need to choose a character
set (standard, URL-safe, etc) and padding suffix (yes/no).
The <code>Config</code> struct encapsulates this info. There are some common configs included: <code>STANDARD</code>,
<code>URL_SAFE</code>, etc. You can also make your own <code>Config</code> if needed.</p>
<p>The functions that don’t have <code>config</code> in the name (e.g. <code>encode()</code> and <code>decode()</code>) use the
<code>STANDARD</code> config .</p>
<p>The functions that write to a slice (the ones that end in <code>_slice</code>) are generally the fastest
because they don’t need to resize anything. If it fits in your workflow and you care about
performance, keep using the same buffer (growing as need be) and use the <code>_slice</code> methods for
the best performance.</p>
<h2 id="encoding"><a href="#encoding">Encoding</a></h2>
<p>Several different encoding functions are available to you depending on your desire for
convenience vs performance.</p>
<div><table><thead><tr><th>Function</th><th>Output</th><th>Allocates</th></tr></thead><tbody>
<tr><td><code>encode</code></td><td>Returns a new <code>String</code></td><td>Always</td></tr>
<tr><td><code>encode_config</code></td><td>Returns a new <code>String</code></td><td>Always</td></tr>
<tr><td><code>encode_config_buf</code></td><td>Appends to provided <code>String</code></td><td>Only if <code>String</code> needs to grow</td></tr>
<tr><td><code>encode_config_slice</code></td><td>Writes to provided <code>&amp;[u8]</code></td><td>Never</td></tr>
</tbody></table>
</div>
<p>All of the encoding functions that take a <code>Config</code> will pad as per the config.</p>
<h2 id="decoding"><a href="#decoding">Decoding</a></h2>
<p>Just as for encoding, there are different decoding functions available.</p>
<div><table><thead><tr><th>Function</th><th>Output</th><th>Allocates</th></tr></thead><tbody>
<tr><td><code>decode</code></td><td>Returns a new <code>Vec&lt;u8&gt;</code></td><td>Always</td></tr>
<tr><td><code>decode_config</code></td><td>Returns a new <code>Vec&lt;u8&gt;</code></td><td>Always</td></tr>
<tr><td><code>decode_config_buf</code></td><td>Appends to provided <code>Vec&lt;u8&gt;</code></td><td>Only if <code>Vec</code> needs to grow</td></tr>
<tr><td><code>decode_config_slice</code></td><td>Writes to provided <code>&amp;[u8]</code></td><td>Never</td></tr>
</tbody></table>
</div>
<p>Unlike encoding, where all possible input is valid, decoding can fail (see <code>DecodeError</code>).</p>
<p>Input can be invalid because it has invalid characters or invalid padding. (No padding at all is
valid, but excess padding is not.) Whitespace in the input is invalid.</p>
<h2 id="read-and-write"><a href="#read-and-write"><code>Read</code> and <code>Write</code></a></h2>
<p>To map a <code>Read</code> of b64 bytes to the decoded bytes, wrap a reader (file, network socket, etc)
with <code>base64::read::DecoderReader</code>. To write raw bytes and have them b64 encoded on the fly,
wrap a writer with <code>base64::write::EncoderWriter</code>. There is some performance overhead (15% or
so) because of the necessary buffer shuffling – still fast enough that almost nobody cares.
Also, these implementations do not heap allocate.</p>
<h2 id="panics"><a href="#panics">Panics</a></h2>
<p>If length calculations result in overflowing <code>usize</code>, a panic will result.</p>
<p>The <code>_slice</code> flavors of encode or decode will panic if the provided output slice is too small,</p>
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="display/index.html" title="base64::display mod">display</a></div><div class="item-right docblock-short">Enables base64’d output anywhere you might use a <code>Display</code> implementation, like a format string.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="read/index.html" title="base64::read mod">read</a></div><div class="item-right docblock-short">Implementations of <code>io::Read</code> to transparently decode base64.</div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="write/index.html" title="base64::write mod">write</a></div><div class="item-right docblock-short">Implementations of <code>io::Write</code> to transparently handle base64.</div></div></div><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Config.html" title="base64::Config struct">Config</a></div><div class="item-right docblock-short">Contains configuration parameters for base64 encoding</div></div></div><h2 id="enums" class="small-section-header"><a href="#enums">Enums</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.CharacterSet.html" title="base64::CharacterSet enum">CharacterSet</a></div><div class="item-right docblock-short">Available encoding character sets</div></div><div class="item-row"><div class="item-left module-item"><a class="enum" href="enum.DecodeError.html" title="base64::DecodeError enum">DecodeError</a></div><div class="item-right docblock-short">Errors that can occur while decoding.</div></div></div><h2 id="constants" class="small-section-header"><a href="#constants">Constants</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.BCRYPT.html" title="base64::BCRYPT constant">BCRYPT</a></div><div class="item-right docblock-short">Bcrypt character set</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.BINHEX.html" title="base64::BINHEX constant">BINHEX</a></div><div class="item-right docblock-short">BinHex character set</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.CRYPT.html" title="base64::CRYPT constant">CRYPT</a></div><div class="item-right docblock-short">As per <code>crypt(3)</code> requirements</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.IMAP_MUTF7.html" title="base64::IMAP_MUTF7 constant">IMAP_MUTF7</a></div><div class="item-right docblock-short">IMAP modified UTF-7 requirements</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.STANDARD.html" title="base64::STANDARD constant">STANDARD</a></div><div class="item-right docblock-short">Standard character set with padding.</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.STANDARD_NO_PAD.html" title="base64::STANDARD_NO_PAD constant">STANDARD_NO_PAD</a></div><div class="item-right docblock-short">Standard character set without padding.</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.URL_SAFE.html" title="base64::URL_SAFE constant">URL_SAFE</a></div><div class="item-right docblock-short">URL-safe character set with padding</div></div><div class="item-row"><div class="item-left module-item"><a class="constant" href="constant.URL_SAFE_NO_PAD.html" title="base64::URL_SAFE_NO_PAD constant">URL_SAFE_NO_PAD</a></div><div class="item-right docblock-short">URL-safe character set without padding</div></div></div><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.decode.html" title="base64::decode fn">decode</a></div><div class="item-right docblock-short">Decode from string reference as octets.
Returns a Result containing a Vec<u8>.
Convenience <code>decode_config(input, base64::STANDARD);</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.decode_config.html" title="base64::decode_config fn">decode_config</a></div><div class="item-right docblock-short">Decode from string reference as octets.
Returns a Result containing a Vec<u8>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.decode_config_buf.html" title="base64::decode_config_buf fn">decode_config_buf</a></div><div class="item-right docblock-short">Decode from string reference as octets.
Writes into the supplied buffer to avoid allocation.
Returns a Result containing an empty tuple, aka ().</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.decode_config_slice.html" title="base64::decode_config_slice fn">decode_config_slice</a></div><div class="item-right docblock-short">Decode the input into the provided output slice.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.encode.html" title="base64::encode fn">encode</a></div><div class="item-right docblock-short">Encode arbitrary octets as base64.
Returns a String.
Convenience for <code>encode_config(input, base64::STANDARD);</code>.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.encode_config.html" title="base64::encode_config fn">encode_config</a></div><div class="item-right docblock-short">Encode arbitrary octets as base64.
Returns a String.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.encode_config_buf.html" title="base64::encode_config_buf fn">encode_config_buf</a></div><div class="item-right docblock-short">Encode arbitrary octets as base64.
Writes into the supplied output buffer, which will grow the buffer if needed.</div></div><div class="item-row"><div class="item-left module-item"><a class="fn" href="fn.encode_config_slice.html" title="base64::encode_config_slice fn">encode_config_slice</a></div><div class="item-right docblock-short">Encode arbitrary octets as base64.
Writes into the supplied output buffer.</div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="base64" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>