### Use URL-Safe Base64 Engine Source: https://docs.rs/base64/latest/base64/index.html Shows how to use the URL-safe base64 alphabet, which replaces '+' and '/' with '-' and '_', respectively. This example explicitly imports the engine. ```rust use base64::{engine::general_purpose::URL_SAFE, Engine as _}; assert_eq!(URL_SAFE.decode(b"-uwgVQA=")?, b"\xFA\xEC\x20\x55\0"); assert_eq!(URL_SAFE.encode(b"\xFF\xEC\x20\x55\0"), "_-wgVQA="); ``` -------------------------------- ### Custom Base64 Engine Configuration Source: https://docs.rs/base64/latest/base64/index.html Provides an example of creating a custom base64 engine with a non-standard alphabet and specific decoding/encoding padding behaviors. ```rust use base64::{engine, alphabet, Engine as _}; // bizarro-world base64: +/ as the first symbols instead of the last let alphabet = alphabet::Alphabet::new("+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") .unwrap(); // a very weird config that encodes with padding but requires no padding when decoding...? let crazy_config = engine::GeneralPurposeConfig::new() .with_decode_allow_trailing_bits(true) .with_encode_padding(true) .with_decode_padding_mode(engine::DecodePaddingMode::RequireNone); let crazy_engine = engine::GeneralPurpose::new(&alphabet, crazy_config); let encoded = crazy_engine.encode(b"abc 123"); ``` -------------------------------- ### Get encode padding setting Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Returns a boolean indicating whether padding is added after the encoded output. ```rust fn encode_padding(&self) -> bool ``` -------------------------------- ### Get TypeId of GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Gets the `TypeId` of the configuration. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Use Standard Base64 Engine with Prelude Source: https://docs.rs/base64/latest/base64/index.html Demonstrates decoding and encoding using the standard base64 alphabet and default padding via the prelude for a minimal import footprint. ```rust use base64::prelude::*; assert_eq!(BASE64_STANDARD.decode(b"+uwgVQA=")?, b"\xFA\xEC\x20\x55\0"); assert_eq!(BASE64_STANDARD.encode(b"\xFF\xEC\x20\x55\0"), "/+wgVQA="); ``` -------------------------------- ### TypeId Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Gets the TypeId of the current object. ```APIDOC ## type_id ### Description Gets the `TypeId` of `self`. ### Method `type_id(&self) -> TypeId` ``` -------------------------------- ### From GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Returns the argument unchanged. ```rust fn from(t: T) -> T ``` -------------------------------- ### Create GeneralPurposeConfig with new() Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new configuration with default settings: padding enabled, trailing bits allowed, and requiring canonical padding. ```rust pub const fn new() -> Self ``` -------------------------------- ### GeneralPurposeConfig::new Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new config with default settings: padding enabled, decode_allow_trailing_bits disabled, and RequireCanonicalPadding mode. ```APIDOC ## GeneralPurposeConfig::new ### Description Creates a new config with `padding` = `true`, `decode_allow_trailing_bits` = `false`, and `decode_padding_mode = DecodePaddingMode::RequireCanonicalPadding`. ### Returns - `Self`: A new `GeneralPurposeConfig` instance. ``` -------------------------------- ### GeneralPurpose::new Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Creates a `GeneralPurpose` engine from a given `Alphabet` and `GeneralPurposeConfig`. It's recommended to cache initialized engines if they will be used repeatedly. ```APIDOC ## GeneralPurpose::new ### Description Create a `GeneralPurpose` engine from an Alphabet. While not very expensive to initialize, ideally these should be cached if the engine will be used repeatedly. ### Signature ```rust pub const fn new(alphabet: &Alphabet, config: GeneralPurposeConfig) -> Self ``` ``` -------------------------------- ### Get the inner reader from DecoderReader Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Unwraps the DecoderReader to retrieve the original reader. Note that the internal buffering of DecoderReader means the state of the inner reader is unspecified after use. ```rust pub fn into_inner(self) -> R ``` -------------------------------- ### Estimate Decoded Length Source: https://docs.rs/base64/latest/base64/fn.decoded_len_estimate.html Use this function to get a safe estimate for the size of a buffer needed to decode base64 data. The estimate may be up to 2 bytes larger than the actual decoded length. ```rust use base64::decoded_len_estimate; assert_eq!(3, decoded_len_estimate(1)); assert_eq!(3, decoded_len_estimate(2)); assert_eq!(3, decoded_len_estimate(3)); assert_eq!(3, decoded_len_estimate(4)); // start of the next quad of encoded symbols assert_eq!(6, decoded_len_estimate(5)); ``` -------------------------------- ### Custom Base64 Engine Configuration Source: https://docs.rs/base64/latest/base64/index.html Explains how to create a custom base64 engine with specific alphabet and padding configurations. ```APIDOC ## Custom Base64 Engine Configuration ### Description This example shows how to create a fully customized base64 engine by defining a new alphabet and specific decoding/encoding configurations. ### Method `GeneralPurpose::new` constructor with custom `Alphabet` and `GeneralPurposeConfig`. ### Parameters - `alphabet`: A reference to an `Alphabet` struct defining the character set. - `config`: A `GeneralPurposeConfig` struct for detailed behavior. ### Request Example ```rust use base64::{engine, alphabet, Engine as _}; // Define a custom alphabet (e.g., '+' and '/' as the first symbols) let alphabet = alphabet::Alphabet::new("+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789").unwrap(); // Define a custom configuration let crazy_config = engine::GeneralPurposeConfig::new() .with_decode_allow_trailing_bits(true) // Allow trailing bits during decoding .with_encode_padding(true) // Enable padding during encoding .with_decode_padding_mode(engine::DecodePaddingMode::RequireNone); // Require no padding during decoding // Create the custom engine let crazy_engine = engine::GeneralPurpose::new(&alphabet, crazy_config); // Use the custom engine for encoding let encoded = crazy_engine.encode(b"abc 123"); ``` ### Response #### Success Response - `encode` returns `String` with the data encoded using the custom engine. #### Response Example ```rust // The exact output depends on the custom alphabet and config. // For the example alphabet and config, the output would be: // assert_eq!(encoded, "+/ABCDEFG123"); // Example output, actual may vary ``` ``` -------------------------------- ### Into GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Calls `U::from(self)` for conversion. ```rust fn into(self) -> U ``` -------------------------------- ### Create and Use a Custom Alphabet Source: https://docs.rs/base64/latest/base64/alphabet/struct.Alphabet.html Demonstrates how to create a custom base64 alphabet from a string and use it with a GeneralPurpose engine. Ensure the alphabet string contains 64 unique, printable ASCII characters, excluding '='. ```rust let custom = base64::alphabet::Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap(); let engine = base64::engine::GeneralPurpose::new( &custom, base64::engine::general_purpose::PAD); ``` -------------------------------- ### Create GeneralPurposeConfig with custom padding Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Instantiate a new configuration with encoding padding disabled. Further customizations can be applied using available `.with_*` methods. ```rust let config = GeneralPurposeConfig::new() .with_encode_padding(false); ``` -------------------------------- ### Base64Display::new Source: https://docs.rs/base64/latest/base64/display/struct.Base64Display.html Creates a new Base64Display instance. This wrapper facilitates the base64 encoding of byte slices directly within format strings, avoiding unnecessary heap allocations. ```APIDOC ## Base64Display::new ### Description Creates a `Base64Display` with the provided engine. ### Signature ```rust pub fn new<'a, 'e, E: Engine>(bytes: &'a [u8], engine: &'e E) -> Base64Display<'a, 'e, E> ``` ### Parameters * `bytes`: A slice of bytes to be encoded. * `engine`: The base64 engine to use for encoding. ``` -------------------------------- ### GeneralPurposeConfig::with_decode_allow_trailing_bits Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new config with the specified decode_allow_trailing_bits setting. ```APIDOC ## GeneralPurposeConfig::with_decode_allow_trailing_bits ### Description Creates a new config based on `self` with an updated `decode_allow_trailing_bits` setting. If `true`, invalid trailing bits in base64 input will be silently ignored; otherwise, `DecodeError::InvalidLastSymbol` will be emitted. ### Parameters - `allow` (bool) - `true` to allow trailing bits, `false` to disallow. ### Returns - `Self`: A new `GeneralPurposeConfig` instance with the updated `decode_allow_trailing_bits` setting. ``` -------------------------------- ### Format GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Formats the configuration value using the given formatter. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Standard Base64 Encoding and Decoding Source: https://docs.rs/base64/latest/base64/index.html Demonstrates the use of the standard base64 alphabet and default padding for encoding and decoding byte slices. ```APIDOC ## STANDARD Base64 Encoding and Decoding ### Description This example shows how to use the `BASE64_STANDARD` engine for basic base64 encoding and decoding. ### Method `decode` and `encode` methods on the `BASE64_STANDARD` engine. ### Parameters None explicitly shown for these basic operations. ### Request Example ```rust use base64::prelude::* // Decoding example let decoded_bytes = BASE64_STANDARD.decode(b"/+wgVQA=")?; // Encoding example let encoded_string = BASE64_STANDARD.encode(b"\xFF\xEC\x20\x55\0"); ``` ### Response #### Success Response - `decode` returns `Result, DecodeError>` - `encode` returns `String` #### Response Example ```rust // For decode: assert_eq!(decoded_bytes, b"\xFA\xEC\x20\x55\0"); // For encode: assert_eq!(encoded_string, "/+wgVQA="); ``` ``` -------------------------------- ### Create GeneralPurpose Engine Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Creates a `GeneralPurpose` engine using a specified `Alphabet` and `GeneralPurposeConfig`. It's recommended to cache initialized engines if they will be used repeatedly. ```rust pub const fn new(alphabet: &Alphabet, config: GeneralPurposeConfig) -> Self ``` -------------------------------- ### Base64 Encoding with Standard Padding Source: https://docs.rs/base64/latest/base64/index.html Illustrates the behavior of the standard base64 engine with different input lengths, showing the addition of '=' padding characters to ensure output is a multiple of 4. ```rust use base64::{engine::general_purpose::STANDARD, Engine as _}; assert_eq!(STANDARD.encode(b" "), ""); assert_eq!(STANDARD.encode(b"f"), "Zg=="); assert_eq!(STANDARD.encode(b"fo"), "Zm8="); assert_eq!(STANDARD.encode(b"foo"), "Zm9v"); ``` -------------------------------- ### Create Base64Display Instance Source: https://docs.rs/base64/latest/base64/display/struct.Base64Display.html Constructs a new Base64Display instance. This method takes a reference to the byte slice to be encoded and a reference to the base64 engine to be used for encoding. ```rust pub fn new(bytes: &'a [u8], engine: &'e E) -> Base64Display<'a, 'e, E> ``` -------------------------------- ### Clone from GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Performs copy-assignment from a source configuration. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Borrow GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Immutably borrows the configuration. ```rust fn borrow(&self) -> &T ``` -------------------------------- ### Create and use DecoderReader Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Instantiate DecoderReader with a source reader and a base64 engine. Then, read decoded data into a buffer. Errors from the underlying reader or decoding issues are handled via `Result`. ```rust use std::io::Read; use std::io::Cursor; use base64::engine::general_purpose; // use a cursor as the simplest possible `Read` -- in real code this is probably a file, etc. let mut wrapped_reader = Cursor::new(b"YXNkZg=="); let mut decoder = base64::read::DecoderReader::new( &mut wrapped_reader, &general_purpose::STANDARD); // handle errors as you normally would let mut result = Vec::new(); decoder.read_to_end(&mut result).unwrap(); assert_eq!(b"asdf", &result[..]); ``` -------------------------------- ### Use Standard Base64 Encoding Without Padding Source: https://docs.rs/base64/latest/base64/prelude/index.html Demonstrates how to use the `BASE64_STANDARD_NO_PAD` engine for encoding bytes to a base64 string. Ensure the `Engine` trait is in scope. ```rust use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD}; assert_eq!("c29tZSBieXRlcw", &BASE64_STANDARD_NO_PAD.encode(b"some bytes")); ``` -------------------------------- ### Create a by-reference adapter Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Creates a "by reference" adapter for the `Read` instance. This allows mutable borrowing of the reader. ```rust fn by_ref(&mut self) -> &mut Self ``` -------------------------------- ### Default GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Provides a default configuration by delegating to `GeneralPurposeConfig::new()`. ```rust fn default() -> Self ``` -------------------------------- ### GeneralPurposeConfig::with_decode_padding_mode Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new config with the specified decode padding mode. ```APIDOC ## GeneralPurposeConfig::with_decode_padding_mode ### Description Creates a new config based on `self` with an updated `decode_padding_mode` setting. This controls how padding characters are handled during decoding. ### Parameters - `mode` (DecodePaddingMode) - The desired padding mode (`DecodePaddingMode::RequireCanonicalPadding`, `DecodePaddingMode::RequireNoPadding`, or `DecodePaddingMode::Indifferent`). ### Returns - `Self`: A new `GeneralPurposeConfig` instance with the updated `decode_padding_mode` setting. ``` -------------------------------- ### Clone GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Returns a duplicate of the configuration value. ```rust fn clone(&self) -> GeneralPurposeConfig ``` -------------------------------- ### by_ref Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Creates a "by reference" adapter for this instance of `Write`. This allows mutable borrowing of the writer. ```APIDOC ## fn by_ref(&mut self) -> &mut Self ### Description Creates a “by reference” adapter for this instance of `Write`. ``` -------------------------------- ### Memory Allocation Options for Decoding and Encoding Source: https://docs.rs/base64/latest/base64/index.html Details the different methods available for decoding and encoding, focusing on memory allocation strategies. ```APIDOC ## Memory Allocation Options for Decoding and Encoding ### Description This section outlines the various methods provided by the `Engine` trait for decoding and encoding, highlighting their memory allocation behavior. ### Methods and Memory Allocation | Method | Output | Allocates memory | |--------------------|---------------------|-------------------| | `Engine::decode` | returns a new `Vec` | always | | `Engine::decode_vec` | appends to provided `Vec` | if `Vec` lacks capacity | | `Engine::decode_slice` | writes to provided `&[u8]` | never | *Note: Similar methods exist for encoding, typically returning `String` or writing to a buffer.* ``` -------------------------------- ### GeneralPurposeConfig::with_encode_padding Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new config with the specified encode padding setting. ```APIDOC ## GeneralPurposeConfig::with_encode_padding ### Description Creates a new config based on `self` with an updated `padding` setting. If `padding` is `true`, encoding will append either 1 or 2 `=` padding characters as needed to produce an output whose length is a multiple of 4. ### Parameters - `padding` (bool) - `true` to enable padding, `false` to disable. ### Returns - `Self`: A new `GeneralPurposeConfig` instance with the updated padding setting. ``` -------------------------------- ### Decode to Vec using Standard and Custom Engines Source: https://docs.rs/base64/latest/base64/engine/trait.Engine.html Demonstrates decoding a base64 string into a Vec using both the standard engine and a custom engine configuration. Ensure the buffer is cleared if reusing it for multiple decodings. ```rust use base64::{Engine as _, alphabet, engine::{self, general_purpose}}; const CUSTOM_ENGINE: engine::GeneralPurpose = engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::PAD); fn main() { use base64::Engine; let mut buffer = Vec::::new(); // with the default engine general_purpose::STANDARD .decode_vec("aGVsbG8gd29ybGR+Cg==", &mut buffer,).unwrap(); println!("{:?}", buffer); buffer.clear(); // with a custom engine CUSTOM_ENGINE.decode_vec( "aGVsbG8gaW50ZXJuZXR-Cg==", &mut buffer, ).unwrap(); println!("{:?}", buffer); } ``` -------------------------------- ### Create and use EncoderWriter Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Demonstrates creating an EncoderWriter with a Vec as the delegate writer and writing data to it. The finish() method is called to encode remaining bytes and retrieve the encoded data. ```rust use std::io::Write; use base64::engine::general_purpose; // use a vec as the simplest possible `Write` -- in real code this is probably a file, etc. let mut enc = base64::write::EncoderWriter::new(Vec::new(), &general_purpose::STANDARD); // handle errors as you normally would enc.write_all(b"asdf").unwrap(); // could leave this out to be called by Drop, if you don't care // about handling errors or getting the delegate writer back let delegate = enc.finish().unwrap(); // base64 was written to the writer assert_eq!(b"YXNkZg==", &delegate[..]); ``` -------------------------------- ### Build a Static Custom Alphabet Source: https://docs.rs/base64/latest/base64/alphabet/struct.Alphabet.html Shows how to define a custom base64 alphabet as a static constant. This method uses a match statement with `panic!` for error handling, as `Result::unwrap()` is not yet const-compatible. ```rust use base64::alphabet::Alphabet; static CUSTOM: Alphabet = { // Result::unwrap() isn't const yet, but panic!() is OK match Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") { Ok(x) => x, Err(_) => panic!("creation of alphabet failed"), } }; ``` -------------------------------- ### URL-Safe Base64 Encoding and Decoding Source: https://docs.rs/base64/latest/base64/index.html Illustrates how to use the URL-safe base64 alphabet, which replaces '+' and '/' with '-' and '_'. ```APIDOC ## URL-Safe Base64 Encoding and Decoding ### Description This example demonstrates using the `URL_SAFE` engine for base64 encoding and decoding, suitable for URLs. ### Method `decode` and `encode` methods on the `URL_SAFE` engine. ### Parameters None explicitly shown for these basic operations. ### Request Example ```rust use base64::{engine::general_purpose::URL_SAFE, Engine as _}; // Decoding example let decoded_bytes = URL_SAFE.decode(b"-uwgVQA=")?; // Encoding example let encoded_string = URL_SAFE.encode(b"\xFF\xEC\x20\x55\0"); ``` ### Response #### Success Response - `decode` returns `Result, DecodeError>` - `encode` returns `String` #### Response Example ```rust // For decode: assert_eq!(decoded_bytes, b"\xFA\xEC\x20\x55\0"); // For encode: assert_eq!(encoded_string, "_-wgVQA="); ``` ``` -------------------------------- ### STANDARD_NO_PAD Source: https://docs.rs/base64/latest/base64/engine/general_purpose/constant.STANDARD_NO_PAD.html A GeneralPurpose engine using the alphabet::STANDARD base64 alphabet and NO_PAD config. ```APIDOC ## STANDARD_NO_PAD ### Description A GeneralPurpose engine using the alphabet::STANDARD base64 alphabet and NO_PAD config. ### Constant Signature ```rust pub const STANDARD_NO_PAD: GeneralPurpose; ``` ``` -------------------------------- ### try_into Method Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Performs the conversion from one type to another, returning a Result. ```APIDOC #### fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### BorrowMut GeneralPurposeConfig Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Mutably borrows the configuration. ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### TryFrom Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Attempts to convert a value into another type, returning a `Result`. ```APIDOC ## try_from ### Description Performs the conversion. ### Method `try_from(value: U) -> Result>::Error>` ### Associated Types - `Error`: The type returned in the event of a conversion error. ``` -------------------------------- ### Limit read bytes Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Creates an adapter that will read at most a specified limit of bytes from the reader. Reads beyond the limit will return 0. ```rust fn take(self, limit: u64) -> Take ``` -------------------------------- ### Chain with another reader Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Creates an adapter that chains this reader with another. Reads will be sequential from this reader first, then the next. ```rust fn chain(self, next: R) -> Chain ``` -------------------------------- ### STANDARD Constant Source: https://docs.rs/base64/latest/base64/engine/general_purpose/constant.STANDARD.html This constant represents a pre-configured base64 engine that uses the standard alphabet and includes padding. ```APIDOC ## STANDARD ### Description A `GeneralPurpose` engine using the `alphabet::STANDARD` base64 alphabet and `PAD` config. ### Type Signature ```rust pub const STANDARD: GeneralPurpose; ``` ``` -------------------------------- ### Implement Display for Base64 Output Source: https://docs.rs/base64/latest/base64/index.html Use Base64Display to easily implement the Display trait for base64 encoded byte slices. This is useful for formatting output. ```rust use base64::{display::Base64Display, engine::general_purpose::STANDARD}; let value = Base64Display::new(b"\0\x01\x02\x03", &STANDARD); assert_eq!("base64: AAECAw==", format!("base64: {}", value)); ``` -------------------------------- ### TryFrom for T Source: https://docs.rs/base64/latest/base64/enum.DecodeError.html Provides a way to attempt a conversion from one type to another, returning a Result. ```APIDOC ## impl TryFrom for T ### Associated Types #### type Error = Infallible The type returned in the event of a conversion error. This specific type indicates that conversion errors are not possible. ### Methods #### fn try_from(value: U) -> Result>::Error> Performs the conversion from type `U` into type `T`. Returns `Ok(T)` on success or `Err(Infallible)` if the conversion fails (though `Infallible` implies failure is impossible in this context). ``` -------------------------------- ### Build a Lazy Custom Alphabet Source: https://docs.rs/base64/latest/base64/alphabet/struct.Alphabet.html Illustrates creating a custom base64 alphabet lazily using the `once_cell::sync::Lazy` type. This is useful for avoiding initialization costs until the alphabet is first accessed. ```rust use base64({ alphabet::Alphabet, engine::{general_purpose::GeneralPurpose, GeneralPurposeConfig}, }); use once_cell::sync::Lazy; static CUSTOM: Lazy = Lazy::new(|| Alphabet::new("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").unwrap() ); ``` -------------------------------- ### TryInto Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Attempts to convert a value into another type using `TryFrom`, returning a `Result`. ```APIDOC ## try_into ### Description Performs the conversion. ### Method `try_into(self) -> Result>::Error>` ### Associated Types - `Error`: The type returned in the event of a conversion error. ``` -------------------------------- ### Display for Base64Display Source: https://docs.rs/base64/latest/base64/display/struct.Base64Display.html Implements the `Display` trait for `Base64Display`, allowing it to be formatted directly into strings using the standard Rust formatting macros. ```APIDOC ## impl Display for Base64Display ### Description Formats the value using the given formatter. This allows `Base64Display` to be used directly with formatting macros like `println!` or `format!`. ### Signature ```rust fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error> ``` ### Parameters * `formatter`: The formatter to write the output to. ### Returns A `Result` indicating success or failure during formatting. ``` -------------------------------- ### Alphabet::new Source: https://docs.rs/base64/latest/base64/alphabet/struct.Alphabet.html Creates a new Alphabet from a string of 64 unique printable ASCII bytes. The '=' byte is not allowed. ```APIDOC ## pub const fn new(alphabet: &str) -> Result Create an `Alphabet` from a string of 64 unique printable ASCII bytes. The `=` byte is not allowed as it is used for padding. ``` -------------------------------- ### Into Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Converts a value into another type that implements `From`. ```APIDOC ## into ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Method `into(self) -> U` ``` -------------------------------- ### write_all_vectored Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Attempts to write multiple buffers into this writer. This is a nightly-only experimental API. ```APIDOC ## fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error> ### Description Attempts to write multiple buffers into this writer. This is a nightly-only experimental API. ``` -------------------------------- ### write_all Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Attempts to write an entire buffer into this writer. This method ensures that the whole buffer is written, returning an error if it cannot be completed. ```APIDOC ## fn write_all(&mut self, buf: &[u8]) -> Result<(), Error> ### Description Attempts to write an entire buffer into this writer. ``` -------------------------------- ### Update encoding padding setting Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new configuration based on the current one, but with the specified padding behavior for encoding. Padding adds '=' characters to ensure output length is a multiple of 4. ```rust pub const fn with_encode_padding(self, padding: bool) -> Self ``` -------------------------------- ### BorrowMut Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Provides mutable borrowing capabilities. ```APIDOC ## borrow_mut ### Description Mutably borrows from an owned value. ### Method `borrow_mut(&mut self) -> &mut T` ``` -------------------------------- ### write Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Encodes input data and writes it to the delegate writer. It handles buffering of encoded data if the delegate writer cannot accept all data at once. Returns the number of bytes of input consumed. ```APIDOC ## fn write(&mut self, input: &[u8]) -> Result ### Description Encode input and then write to the delegate writer. Under non-error circumstances, this returns `Ok` with the value being the number of bytes of `input` consumed. The value may be `0`, which interacts poorly with `write_all`, which interprets `Ok(0)` as an error, despite it being allowed by the contract of `write`. If the previous call to `write` provided more (encoded) data than the delegate writer could accept in a single call to its `write`, the remaining data is buffered. As long as buffered data is present, subsequent calls to `write` will try to write the remaining buffered data to the delegate and return either `Ok(0)` – and therefore not consume any of `input` – or an error. ### Errors Any errors emitted by the delegate writer are returned. ``` -------------------------------- ### Engine Trait Implementations for GeneralPurpose Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Provides methods for encoding and decoding data using the `GeneralPurpose` engine, including various ways to handle input and output buffers. ```APIDOC ## Engine Trait Implementations for GeneralPurpose ### Description Provides methods for encoding and decoding data using the `GeneralPurpose` engine, including various ways to handle input and output buffers. ### Methods #### `config()` Returns the configuration for this engine. #### `encode>(input: T) -> String` Encode arbitrary octets as base64 using the provided `Engine`. Returns a `String`. #### `encode_string>(input: T, output_buf: &mut String)` Encode arbitrary octets as base64 into a supplied `String`. Writes into the supplied `String`, which may allocate if its internal buffer isn’t big enough. #### `encode_slice>(input: T, output_buf: &mut [u8]) -> Result` Encode arbitrary octets as base64 into a supplied slice. Writes into the supplied output buffer. #### `decode>(input: T) -> Result, DecodeError>` Decode the input into a new `Vec`. #### `decode_vec>(input: T, buffer: &mut Vec) -> Result<(), DecodeError>` Decode the `input` into the supplied `buffer`. #### `decode_slice>(input: T, output: &mut [u8]) -> Result` Decode the input into the provided output slice. #### `decode_slice_unchecked>(input: T, output: &mut [u8]) -> Result` Decode the input into the provided output slice. ``` -------------------------------- ### Clone to uninitialized memory (nightly) Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Nightly-only experimental API. Performs copy-assignment from self to uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Config Trait Definition Source: https://docs.rs/base64/latest/base64/engine/trait.Config.html Defines the minimal configuration for base64 encoding engines. Implementors must provide the encode_padding method. ```rust pub trait Config { // Required method fn encode_padding(&self) -> bool; } ``` -------------------------------- ### Use Base64Display with Format Strings Source: https://docs.rs/base64/latest/base64/display/index.html Use `Base64Display` to format byte slices as base64 strings within format strings. This wrapper implements the `Display` trait and avoids heap allocations. ```rust use base64::{display::Base64Display, engine::general_purpose::STANDARD}; let data = vec![0x0, 0x1, 0x2, 0x3]; let wrapper = Base64Display::new(&data, &STANDARD); assert_eq!("base64: AAECAw==", format!("base64: {}", wrapper)); ``` -------------------------------- ### Update decode padding mode setting Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new configuration based on the current one, with an updated setting for how padding is handled during decoding. Options include requiring canonical padding, indifferent to padding, or requiring no padding. ```rust pub const fn with_decode_padding_mode(self, mode: DecodePaddingMode) -> Self ``` -------------------------------- ### NO_PAD Source: https://docs.rs/base64/latest/base64/engine/general_purpose/constant.NO_PAD.html This constant provides a configuration for the GeneralPurposeEngine that disables padding for both encoding and decoding operations. When using this configuration, encoded output will not have any padding characters, and decoding will fail if padding is present. ```APIDOC ## NO_PAD ### Description Don’t add padding when encoding, and require no padding when decoding. ### Constant Signature ```rust pub const NO_PAD: GeneralPurposeConfig; ``` ``` -------------------------------- ### Base64 Encoding without Padding Source: https://docs.rs/base64/latest/base64/index.html Demonstrates encoding without padding characters using the `STANDARD_NO_PAD` engine. ```APIDOC ## Base64 Encoding without Padding ### Description This example shows how to encode data without padding characters using the `STANDARD_NO_PAD` engine. ### Method `encode` method on the `STANDARD_NO_PAD` engine. ### Parameters None explicitly shown for these basic operations. ### Request Example ```rust use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _}; assert_eq!(STANDARD_NO_PAD.encode(b"f"), "Zg"); assert_eq!(STANDARD_NO_PAD.encode(b"fo"), "Zm8"); assert_eq!(STANDARD_NO_PAD.encode(b"foo"), "Zm9v"); ``` ### Response #### Success Response - `encode` returns `String` containing the base64 encoded data without padding. #### Response Example ```rust assert_eq!(STANDARD_NO_PAD.encode(b"f"), "Zg"); assert_eq!(STANDARD_NO_PAD.encode(b"fo"), "Zm8"); assert_eq!(STANDARD_NO_PAD.encode(b"foo"), "Zm9v"); ``` ``` -------------------------------- ### Base64 Encoding without Padding Source: https://docs.rs/base64/latest/base64/index.html Demonstrates encoding using a configuration that omits the '=' padding characters. This is useful when padding is not required for decoding. ```rust use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _}; assert_eq!(STANDARD_NO_PAD.encode(b" "), ""); assert_eq!(STANDARD_NO_PAD.encode(b"f"), "Zg"); assert_eq!(STANDARD_NO_PAD.encode(b"fo"), "Zm8"); assert_eq!(STANDARD_NO_PAD.encode(b"foo"), "Zm9v"); ``` -------------------------------- ### EncoderWriter::new Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Creates a new EncoderWriter that encodes data using the specified engine and writes it to the provided delegate writer. ```APIDOC ## EncoderWriter::new ### Description Create a new encoder that will write to the provided delegate writer. ### Signature ```rust pub fn new<'e, E: Engine, W: Write>(delegate: W, engine: &'e E) -> EncoderWriter<'e, E, W> ``` ### Parameters * **delegate**: The writer to which the base64 encoded data will be written. * **engine**: A reference to the base64 engine to use for encoding. ``` -------------------------------- ### TryFrom<&str> for Alphabet Source: https://docs.rs/base64/latest/base64/alphabet/struct.Alphabet.html Allows creating an Alphabet by trying to convert a string slice. ```APIDOC ### impl TryFrom<&str> for Alphabet #### type Error = ParseAlphabetError The type returned in the event of a conversion error. #### fn try_from(value: &str) -> Result Performs the conversion. ``` -------------------------------- ### TryInto for T Source: https://docs.rs/base64/latest/base64/enum.DecodeError.html Provides a convenient way to attempt a conversion into another type using the TryFrom trait. ```APIDOC ## impl TryInto for T ### Associated Types #### type Error = >::Error The type returned in the event of a conversion error. This is determined by the `Error` type of the `TryFrom` implementation for the target type `U`. ### Methods #### fn try_into(self) -> Result>::Error> Performs the conversion from the current type `T` into the target type `U`. Returns `Ok(U)` on success or an `Err` containing the specific error type if the conversion fails. ``` -------------------------------- ### Buffer base64 in a new String Source: https://docs.rs/base64/latest/base64/write/struct.EncoderStringWriter.html Use EncoderStringWriter::new to create a writer that encodes data into a new String. Ensure to call into_inner() to retrieve the final encoded string. ```rust use std::io::Write; use base64::engine::general_purpose; let mut enc = base64::write::EncoderStringWriter::new(&general_purpose::STANDARD); enc.write_all(b"asdf").unwrap(); // get the resulting String let b64_string = enc.into_inner(); assert_eq!("YXNkZg==", &b64_string); ``` -------------------------------- ### Borrow Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Provides immutable borrowing capabilities. ```APIDOC ## borrow ### Description Immutably borrows from an owned value. ### Method `borrow(&self) -> &T` ``` -------------------------------- ### URL_SAFE_NO_PAD Source: https://docs.rs/base64/latest/base64/engine/general_purpose/constant.URL_SAFE_NO_PAD.html A GeneralPurpose engine using the alphabet::URL_SAFE base64 alphabet and NO_PAD config. ```APIDOC ## Constant URL_SAFE_NO_PAD ### Summary ``` pub const URL_SAFE_NO_PAD: GeneralPurpose; ``` ### Description A GeneralPurpose engine using the alphabet::URL_SAFE base64 alphabet and NO_PAD config. ``` -------------------------------- ### EncoderStringWriter::new Source: https://docs.rs/base64/latest/base64/write/struct.EncoderStringWriter.html Creates a new EncoderStringWriter that encodes data into a new String. ```APIDOC ## EncoderStringWriter::new ### Description Create a EncoderStringWriter that will encode into a new `String` with the provided config. ### Signature ```rust pub fn new(engine: &'e E) -> Self ``` ### Parameters * `engine`: A reference to the base64 engine to use for encoding. ``` -------------------------------- ### DecoderReader::new Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Creates a new DecoderReader that decodes base64 data from an underlying reader. ```APIDOC ## DecoderReader::new ### Description Create a new decoder that will read from the provided reader `r`. ### Signature ```rust pub fn new(reader: R, engine: &'e E) -> Self ``` ### Parameters * `reader`: The underlying reader implementing the `Read` trait. * `engine`: A reference to the base64 engine to use for decoding. ### Example ```rust use std::io::Read; use std::io::Cursor; use base64::engine::general_purpose; let mut wrapped_reader = Cursor::new(b"YXNkZg=="); let mut decoder = base64::read::DecoderReader::new( &mut wrapped_reader, &general_purpose::STANDARD); let mut result = Vec::new(); decoder.read_to_end(&mut result).unwrap(); assert_eq!(b"asdf", &result[..]); ``` ``` -------------------------------- ### Update decode trailing bits setting Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Creates a new configuration based on the current one, with an updated setting for allowing trailing bits during decoding. This is useful for forgivingly decoding base64 from potentially buggy encoders. ```rust pub const fn with_decode_allow_trailing_bits(self, allow: bool) -> Self ``` -------------------------------- ### to_string Source: https://docs.rs/base64/latest/base64/enum.DecodeError.html Converts the value to its string representation. ```APIDOC #### fn to_string(&self) -> String Converts the given value to a `String`. ``` -------------------------------- ### Standard Base64 Encoding with Padding Source: https://docs.rs/base64/latest/base64/prelude/index.html Uses the standard base64 encoding engine with padding characters. This is the most common form of base64 encoding. ```APIDOC ## BASE64_STANDARD ### Description Provides a preconfigured base64 engine that uses the standard alphabet and includes padding characters. ### Usage ```rust use base64::prelude::{Engine as _, BASE64_STANDARD}; let encoded = BASE64_STANDARD.encode(b"some bytes"); let decoded = BASE64_STANDARD.decode(encoded).unwrap(); ``` ### Re-exports `pub use crate::engine::general_purpose::STANDARD as BASE64_STANDARD;` ``` -------------------------------- ### Config Trait Source: https://docs.rs/base64/latest/base64/engine/trait.Config.html The Config trait specifies the essential configuration methods that base64 engines must implement. It includes a method to determine if padding should be added to encoded output. ```APIDOC ## Trait Config ### Summary The minimal level of configuration that engines must support. ```rust pub trait Config { // Required method fn encode_padding(&self) -> bool; } ``` ### Required Methods #### fn encode_padding(&self) -> bool Returns `true` if padding should be added after the encoded output. Padding is added outside the engine’s encode() since the engine may be used to encode only a chunk of the overall output, so it can’t always know when the output is “done” and would therefore need padding (if configured). ``` -------------------------------- ### encode_padding Method Explanation Source: https://docs.rs/base64/latest/base64/engine/trait.Config.html Returns true if padding should be added after the encoded output. Padding is handled outside the engine's encode() method because the engine might encode only a portion of the output and cannot always determine when padding is needed. ```rust fn encode_padding(&self) -> bool; ``` -------------------------------- ### encode Source: https://docs.rs/base64/latest/base64/engine/trait.Engine.html Encodes arbitrary octets as base64 into a String. This is a provided method on the Engine trait. ```APIDOC ## encode>(&self, input: T) -> String ### Description Encode arbitrary octets as base64 using the provided `Engine`. Returns a `String`. ### Method `encode` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use base64::{Engine as _, engine::{self, general_purpose}, alphabet}; let b64 = general_purpose::STANDARD.encode(b"hello world~"); println!("{}", b64); const CUSTOM_ENGINE: engine::GeneralPurpose = engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD); let b64_url = CUSTOM_ENGINE.encode(b"hello internet~"); ``` ### Response #### Success Response (200) - **String**: The base64 encoded string. #### Response Example ``` "aGVsbG8gd29ybGQ+Cg==" ``` ``` -------------------------------- ### Decoding with Padding Errors Source: https://docs.rs/base64/latest/base64/index.html Shows how engines configured for no padding reject inputs containing padding characters. ```APIDOC ## Decoding with Padding Errors ### Description This example demonstrates that engines configured for no padding (like `STANDARD_NO_PAD`) will return an error if the input contains padding characters. ### Method `decode` method on the `STANDARD_NO_PAD` engine. ### Parameters None explicitly shown for these basic operations. ### Request Example ```rust use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _}; // Attempting to decode a string with padding let result = STANDARD_NO_PAD.decode(b"Zm8="); ``` ### Response #### Success Response - `decode` returns `Result, DecodeError>` #### Response Example ```rust use base64::DecodeError; assert_eq!(result, Err(DecodeError::InvalidPadding)); ``` ``` -------------------------------- ### Read a fixed-size array Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Reads and returns a fixed-size array of bytes from the source. This is a nightly-only experimental API. ```rust fn read_array(&mut self) -> Result<[u8; N], Error> ``` -------------------------------- ### GeneralPurpose Struct Definition Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Defines the GeneralPurpose struct, a general-purpose base64 engine. It is designed for broad compatibility and reasonable speed, but is not constant-time. ```rust pub struct GeneralPurpose { /* private fields */ } ``` -------------------------------- ### Encode arbitrary octets to base64 string Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Encodes arbitrary octets into a base64 `String` using the `GeneralPurpose` engine. This method returns a new `String` containing the base64 encoded data. ```rust fn encode>(&self, input: T) -> String ``` -------------------------------- ### Encode arbitrary octets to base64 into a supplied String Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Encodes arbitrary octets into base64 and writes the result into a provided `String` buffer. The buffer may allocate if it is not large enough to hold the encoded data. ```rust fn encode_string>(&self, input: T, output_buf: &mut String) ``` -------------------------------- ### URL-Safe Base64 Encoding with Padding Source: https://docs.rs/base64/latest/base64/prelude/index.html Uses the URL-safe base64 encoding engine with padding characters. Suitable for URLs and filenames when padding is required. ```APIDOC ## BASE64_URL_SAFE ### Description Provides a preconfigured base64 engine that uses the URL-safe alphabet and includes padding characters. ### Usage ```rust use base64::prelude::{Engine as _, BASE64_URL_SAFE}; let encoded = BASE64_URL_SAFE.encode(b"some bytes"); let decoded = BASE64_URL_SAFE.decode(encoded).unwrap(); ``` ### Re-exports `pub use crate::engine::general_purpose::URL_SAFE as BASE64_URL_SAFE;` ``` -------------------------------- ### StrConsumer::consume Source: https://docs.rs/base64/latest/base64/write/trait.StrConsumer.html Consumes the base64 encoded data in the provided string buffer. ```APIDOC ## fn consume(&mut self, buf: &str) ### Description Consume the base64 encoded data in `buf`. ### Method `consume` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response None ### Error Handling None ``` -------------------------------- ### Encode arbitrary octets to base64 into a supplied slice Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurpose.html Encodes arbitrary octets into base64 and writes the result into a provided byte slice. Returns the number of bytes written or an error if the slice is too small. ```rust fn encode_slice>( &self, input: T, output_buf: &mut [u8], ) -> Result ``` -------------------------------- ### write_fmt Source: https://docs.rs/base64/latest/base64/write/struct.EncoderWriter.html Writes a formatted string into this writer, returning any error encountered. This method is useful for writing formatted text directly. ```APIDOC ## fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error> ### Description Writes a formatted string into this writer, returning any error encountered. ``` -------------------------------- ### Read exact bytes into a borrowed cursor Source: https://docs.rs/base64/latest/base64/read/struct.DecoderReader.html Reads the exact number of bytes required to fill the cursor's buffer. This is a nightly-only experimental API. ```rust fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error> ``` -------------------------------- ### Stream Decode with DecoderReader Source: https://docs.rs/base64/latest/base64/index.html Use DecoderReader for streaming base64 decoding from any readable byte stream to standard output. Ensure necessary imports are included. ```rust use base64::{engine::general_purpose::STANDARD, read::DecoderReader}; let mut input = io::stdin(); let mut decoder = DecoderReader::new(&mut input, &STANDARD); io::copy(&mut decoder, &mut io::stdout())?; ``` -------------------------------- ### Encode Data to Base64 String Source: https://docs.rs/base64/latest/base64/engine/trait.Engine.html Encodes arbitrary bytes into a base64 `String`. This method is suitable when a `String` output is desired and allocation is acceptable. It uses the `STANDARD` engine by default or a custom engine. ```rust use base64::{Engine as _, engine::{self, general_purpose}, alphabet}; let b64 = general_purpose::STANDARD.encode(b"hello world~"); println!("{}", b64); const CUSTOM_ENGINE: engine::GeneralPurpose = engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD); let b64_url = CUSTOM_ENGINE.encode(b"hello internet~"); ``` -------------------------------- ### TryFrom Trait Implementation Source: https://docs.rs/base64/latest/base64/engine/general_purpose/struct.GeneralPurposeConfig.html Enables attempting to convert one type into another, returning a Result. ```APIDOC ## Trait: TryFrom ### Description Enables attempting to convert one type (`U`) into another (`T`), returning a `Result`. ### Associated Types #### type Error = Infallible - Description: The type returned in the event of a conversion error. `Infallible` indicates that this conversion will never fail. ### Methods #### fn try_from(value: U) -> Result>::Error> - Description: Performs the conversion from type `U` to type `T`. ``` -------------------------------- ### STANDARD_NO_PAD Constant Definition Source: https://docs.rs/base64/latest/base64/engine/general_purpose/constant.STANDARD_NO_PAD.html This constant defines a GeneralPurpose engine using the standard base64 alphabet and no padding. It's useful for scenarios where padding characters are not desired or expected. ```rust pub const STANDARD_NO_PAD: GeneralPurpose; ``` -------------------------------- ### Standard Base64 Encoding Source: https://docs.rs/base64/latest/base64/prelude/index.html Uses the standard base64 encoding engine without padding. This is a common choice for many applications. ```APIDOC ## BASE64_STANDARD_NO_PAD ### Description Provides a preconfigured base64 engine that uses the standard alphabet and omits padding characters. ### Usage ```rust use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD}; let encoded = BASE64_STANDARD_NO_PAD.encode(b"some bytes"); let decoded = BASE64_STANDARD_NO_PAD.decode(encoded).unwrap(); ``` ### Re-exports `pub use crate::engine::general_purpose::STANDARD_NO_PAD as BASE64_STANDARD_NO_PAD;` ``` -------------------------------- ### Implementing From for DecodeSliceError Source: https://docs.rs/base64/latest/base64/enum.DecodeSliceError.html Allows direct conversion of a DecodeError into a DecodeSliceError. This simplifies error handling by enabling the use of the `?` operator or `into()` method when a DecodeError needs to be treated as a DecodeSliceError. ```rust impl From for DecodeSliceError { fn from(e: DecodeError) -> Self { // Implementation details omitted for brevity } } ```