| <!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="An `Engine` provides low-level encoding and decoding operations that all other higher-level parts of the API use. Users of the library will generally not need to implement this."><meta name="keywords" content="rust, rustlang, rust-lang, Engine"><title>Engine in base64::engine - 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="sidebar-items.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 trait"><!--[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">☰</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="#">Engine</a></h2><div class="sidebar-elems"><section><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Config">Config</a></li><li><a href="#associatedtype.DecodeEstimate">DecodeEstimate</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.config">config</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.decode">decode</a></li><li><a href="#method.decode_slice">decode_slice</a></li><li><a href="#method.decode_slice_unchecked">decode_slice_unchecked</a></li><li><a href="#method.decode_vec">decode_vec</a></li><li><a href="#method.encode">encode</a></li><li><a href="#method.encode_slice">encode_slice</a></li><li><a href="#method.encode_string">encode_string</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In base64::engine</a></h2></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">Trait <a href="../index.html">base64</a>::<wbr><a href="index.html">engine</a>::<wbr><a class="trait" href="#">Engine</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/engine/mod.rs.html#39-349">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust trait"><code>pub trait Engine: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> { |
| type <a href="#associatedtype.Config" class="associatedtype">Config</a>: <a class="trait" href="trait.Config.html" title="trait base64::engine::Config">Config</a>; |
| type <a href="#associatedtype.DecodeEstimate" class="associatedtype">DecodeEstimate</a>: <a class="trait" href="trait.DecodeEstimate.html" title="trait base64::engine::DecodeEstimate">DecodeEstimate</a>; |
| |
| fn <a href="#tymethod.config" class="fnname">config</a>(&self) -> &Self::<a class="associatedtype" href="trait.Engine.html#associatedtype.Config" title="type base64::engine::Engine::Config">Config</a>; |
| |
| fn <a href="#method.encode" class="fnname">encode</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.encode_string" class="fnname">encode_string</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T, output_buf: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>) { ... } |
| <span class="item-spacer"></span> fn <a href="#method.encode_slice" class="fnname">encode_slice</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output_buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br> ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.EncodeSliceError.html" title="enum base64::EncodeSliceError">EncodeSliceError</a>> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.decode" class="fnname">decode</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.decode_vec" class="fnname">decode_vec</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> buffer: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>><br> ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.decode_slice" class="fnname">decode_slice</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br> ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.DecodeSliceError.html" title="enum base64::DecodeSliceError">DecodeSliceError</a>> { ... } |
| <span class="item-spacer"></span> fn <a href="#method.decode_slice_unchecked" class="fnname">decode_slice_unchecked</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br> ) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>> { ... } |
| }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An <code>Engine</code> provides low-level encoding and decoding operations that all other higher-level parts of the API use. Users of the library will generally not need to implement this.</p> |
| <p>Different implementations offer different characteristics. The library currently ships with |
| <a href="general_purpose/struct.GeneralPurpose.html" title="GeneralPurpose">GeneralPurpose</a> that offers good speed and works on any CPU, with more choices |
| coming later, like a constant-time one when side channel resistance is called for, and vendor-specific vectorized ones for more speed.</p> |
| <p>See <a href="general_purpose/constant.STANDARD_NO_PAD.html" title="general_purpose::STANDARD_NO_PAD">general_purpose::STANDARD_NO_PAD</a> if you just want standard base64. Otherwise, when possible, it’s |
| recommended to store the engine in a <code>const</code> so that references to it won’t pose any lifetime |
| issues, and to avoid repeating the cost of engine setup.</p> |
| <p>Since almost nobody will need to implement <code>Engine</code>, docs for internal methods are hidden.</p> |
| </div></details><h2 id="required-associated-types" class="small-section-header">Required Associated Types<a href="#required-associated-types" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.Config" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#41">source</a><h4 class="code-header">type <a href="#associatedtype.Config" class="associatedtype">Config</a>: <a class="trait" href="trait.Config.html" title="trait base64::engine::Config">Config</a></h4></section></summary><div class="docblock"><p>The config type used by this engine</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="associatedtype.DecodeEstimate" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#43">source</a><h4 class="code-header">type <a href="#associatedtype.DecodeEstimate" class="associatedtype">DecodeEstimate</a>: <a class="trait" href="trait.DecodeEstimate.html" title="trait base64::engine::DecodeEstimate">DecodeEstimate</a></h4></section></summary><div class="docblock"><p>The decode estimate used by this engine</p> |
| </div></details></div><h2 id="required-methods" class="small-section-header">Required Methods<a href="#required-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="tymethod.config" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#99">source</a><h4 class="code-header">fn <a href="#tymethod.config" class="fnname">config</a>(&self) -> &Self::<a class="associatedtype" href="trait.Engine.html#associatedtype.Config" title="type base64::engine::Engine::Config">Config</a></h4></section></summary><div class="docblock"><p>Returns the config for this engine.</p> |
| </div></details></div><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.encode" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#117-125">source</a><h4 class="code-header">fn <a href="#method.encode" class="fnname">encode</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T) -> <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Encode arbitrary octets as base64 using the provided <code>Engine</code>. |
| Returns a <code>String</code>.</p> |
| <h5 id="example"><a href="#example">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>base64::{Engine <span class="kw">as _</span>, engine::{<span class="self">self</span>, general_purpose}, alphabet}; |
| |
| <span class="kw">let </span>b64 = general_purpose::STANDARD.encode(<span class="string">b"hello world~"</span>); |
| <span class="macro">println!</span>(<span class="string">"{}"</span>, b64); |
| |
| <span class="kw">const </span>CUSTOM_ENGINE: engine::GeneralPurpose = |
| engine::GeneralPurpose::new(<span class="kw-2">&</span>alphabet::URL_SAFE, general_purpose::NO_PAD); |
| |
| <span class="kw">let </span>b64_url = CUSTOM_ENGINE.encode(<span class="string">b"hello internet~"</span>);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.encode_string" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#148-158">source</a><h4 class="code-header">fn <a href="#method.encode_string" class="fnname">encode_string</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T, output_buf: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>)</h4></section></summary><div class="docblock"><p>Encode arbitrary octets as base64 into a supplied <code>String</code>. |
| Writes into the supplied <code>String</code>, which may allocate if its internal buffer isn’t big enough.</p> |
| <h5 id="example-1"><a href="#example-1">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>base64::{Engine <span class="kw">as _</span>, engine::{<span class="self">self</span>, general_purpose}, alphabet}; |
| <span class="kw">const </span>CUSTOM_ENGINE: engine::GeneralPurpose = |
| engine::GeneralPurpose::new(<span class="kw-2">&</span>alphabet::URL_SAFE, general_purpose::NO_PAD); |
| |
| <span class="kw">fn </span>main() { |
| <span class="kw">let </span><span class="kw-2">mut </span>buf = String::new(); |
| general_purpose::STANDARD.encode_string(<span class="string">b"hello world~"</span>, <span class="kw-2">&mut </span>buf); |
| <span class="macro">println!</span>(<span class="string">"{}"</span>, buf); |
| |
| buf.clear(); |
| CUSTOM_ENGINE.encode_string(<span class="string">b"hello internet~"</span>, <span class="kw-2">&mut </span>buf); |
| <span class="macro">println!</span>(<span class="string">"{}"</span>, buf); |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.encode_slice" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#182-201">source</a><h4 class="code-header">fn <a href="#method.encode_slice" class="fnname">encode_slice</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output_buf: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.EncodeSliceError.html" title="enum base64::EncodeSliceError">EncodeSliceError</a>></h4></section></summary><div class="docblock"><p>Encode arbitrary octets as base64 into a supplied slice. |
| Writes into the supplied output buffer.</p> |
| <p>This is useful if you wish to avoid allocation entirely (e.g. encoding into a stack-resident |
| or statically-allocated buffer).</p> |
| <h5 id="example-2"><a href="#example-2">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>base64::{Engine <span class="kw">as _</span>, engine::general_purpose}; |
| <span class="kw">let </span>s = <span class="string">b"hello internet!"</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buf = Vec::new(); |
| <span class="comment">// make sure we'll have a slice big enough for base64 + padding |
| </span>buf.resize(s.len() * <span class="number">4 </span>/ <span class="number">3 </span>+ <span class="number">4</span>, <span class="number">0</span>); |
| |
| <span class="kw">let </span>bytes_written = general_purpose::STANDARD.encode_slice(s, <span class="kw-2">&mut </span>buf).unwrap(); |
| |
| <span class="comment">// shorten our vec down to just what was written |
| </span>buf.truncate(bytes_written); |
| |
| <span class="macro">assert_eq!</span>(s, general_purpose::STANDARD.decode(<span class="kw-2">&</span>buf).unwrap().as_slice());</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.decode" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#222-234">source</a><h4 class="code-header">fn <a href="#method.decode" class="fnname">decode</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(&self, input: T) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>></h4></section></summary><div class="docblock"><p>Decode the input into a new <code>Vec</code>.</p> |
| <h5 id="example-3"><a href="#example-3">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>base64::{Engine <span class="kw">as _</span>, alphabet, engine::{<span class="self">self</span>, general_purpose}}; |
| |
| <span class="kw">let </span>bytes = general_purpose::STANDARD |
| .decode(<span class="string">"aGVsbG8gd29ybGR+Cg=="</span>).unwrap(); |
| <span class="macro">println!</span>(<span class="string">"{:?}"</span>, bytes); |
| |
| <span class="comment">// custom engine setup |
| </span><span class="kw">let </span>bytes_url = engine::GeneralPurpose::new( |
| <span class="kw-2">&</span>alphabet::URL_SAFE, |
| general_purpose::NO_PAD) |
| .decode(<span class="string">"aGVsbG8gaW50ZXJuZXR-Cg"</span>).unwrap(); |
| <span class="macro">println!</span>(<span class="string">"{:?}"</span>, bytes_url);</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.decode_vec" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#267-291">source</a><h4 class="code-header">fn <a href="#method.decode_vec" class="fnname">decode_vec</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> buffer: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>><br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>></h4></section></summary><div class="docblock"><p>Decode the <code>input</code> into the supplied <code>buffer</code>.</p> |
| <p>Writes into the supplied <code>Vec</code>, which may allocate if its internal buffer isn’t big enough. |
| Returns a <code>Result</code> containing an empty tuple, aka <code>()</code>.</p> |
| <h5 id="example-4"><a href="#example-4">Example</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>base64::{Engine <span class="kw">as _</span>, alphabet, engine::{<span class="self">self</span>, general_purpose}}; |
| <span class="kw">const </span>CUSTOM_ENGINE: engine::GeneralPurpose = |
| engine::GeneralPurpose::new(<span class="kw-2">&</span>alphabet::URL_SAFE, general_purpose::PAD); |
| |
| <span class="kw">fn </span>main() { |
| <span class="kw">use </span>base64::Engine; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = Vec::<u8>::new(); |
| <span class="comment">// with the default engine |
| </span>general_purpose::STANDARD |
| .decode_vec(<span class="string">"aGVsbG8gd29ybGR+Cg=="</span>, <span class="kw-2">&mut </span>buffer,).unwrap(); |
| <span class="macro">println!</span>(<span class="string">"{:?}"</span>, buffer); |
| |
| buffer.clear(); |
| |
| <span class="comment">// with a custom engine |
| </span>CUSTOM_ENGINE.decode_vec( |
| <span class="string">"aGVsbG8gaW50ZXJuZXR-Cg=="</span>, |
| <span class="kw-2">&mut </span>buffer, |
| ).unwrap(); |
| <span class="macro">println!</span>(<span class="string">"{:?}"</span>, buffer); |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.decode_slice" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#304-319">source</a><h4 class="code-header">fn <a href="#method.decode_slice" class="fnname">decode_slice</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.DecodeSliceError.html" title="enum base64::DecodeSliceError">DecodeSliceError</a>></h4></section></summary><div class="docblock"><p>Decode the input into the provided output slice.</p> |
| <p>Returns the number of bytes written to the slice, or an error if <code>output</code> is smaller than |
| the estimated decoded length.</p> |
| <p>This will not write any bytes past exactly what is decoded (no stray garbage bytes at the end).</p> |
| <p>See <a href="../fn.decoded_len_estimate.html" title="crate::decoded_len_estimate">crate::decoded_len_estimate</a> for calculating buffer sizes.</p> |
| <p>See <a href="trait.Engine.html#method.decode_slice_unchecked" title="Engine::decode_slice_unchecked">Engine::decode_slice_unchecked</a> for a version that panics instead of returning an error |
| if the output buffer is too small.</p> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.decode_slice_unchecked" class="method has-srclink"><a class="srclink rightside" href="../../src/base64/engine/mod.rs.html#335-348">source</a><h4 class="code-header">fn <a href="#method.decode_slice_unchecked" class="fnname">decode_slice_unchecked</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a><[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]>>(<br> &self,<br> input: T,<br> output: &mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]<br>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="enum" href="../enum.DecodeError.html" title="enum base64::DecodeError">DecodeError</a>></h4></section></summary><div class="docblock"><p>Decode the input into the provided output slice.</p> |
| <p>Returns the number of bytes written to the slice.</p> |
| <p>This will not write any bytes past exactly what is decoded (no stray garbage bytes at the end).</p> |
| <p>See <a href="../fn.decoded_len_estimate.html" title="crate::decoded_len_estimate">crate::decoded_len_estimate</a> for calculating buffer sizes.</p> |
| <p>See <a href="trait.Engine.html#method.decode_slice" title="Engine::decode_slice">Engine::decode_slice</a> for a version that returns an error instead of panicking if the output |
| buffer is too small.</p> |
| <h5 id="panics"><a href="#panics">Panics</a></h5> |
| <p>Panics if the provided output buffer is too small for the decoded data.</p> |
| </div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Engine-for-GeneralPurpose" class="impl has-srclink"><a class="srclink rightside" href="../../src/base64/engine/general_purpose/mod.rs.html#42-188">source</a><a href="#impl-Engine-for-GeneralPurpose" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="trait.Engine.html" title="trait base64::engine::Engine">Engine</a> for <a class="struct" href="general_purpose/struct.GeneralPurpose.html" title="struct base64::engine::general_purpose::GeneralPurpose">GeneralPurpose</a></h3></section></summary><div class="impl-items"><section id="associatedtype.Config-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Config-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.Config" class="associatedtype">Config</a> = <a class="struct" href="general_purpose/struct.GeneralPurposeConfig.html" title="struct base64::engine::general_purpose::GeneralPurposeConfig">GeneralPurposeConfig</a></h4></section><section id="associatedtype.DecodeEstimate-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.DecodeEstimate-1" class="anchor"></a><h4 class="code-header">type <a href="#associatedtype.DecodeEstimate" class="associatedtype">DecodeEstimate</a> = GeneralPurposeEstimate</h4></section></div></details></div><script src="../../implementors/base64/engine/trait.Engine.js" async></script></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> |