decode_into

Function decode_into 

Source
pub fn decode_into(
    input: &[u8],
    output: &mut [MaybeUninit<u8>],
) -> Result<usize, DecodeIntoSliceError>
Expand description

Decode base64-encoded input into the provided slice.

Returns the amount of bytes written.

ยงExample

use weakauras_codec_base64::{decode, error::DecodeIntoSliceError};

fn main() -> Result<(), DecodeIntoSliceError> {
    let input = b"ivgBS9glGC3BYXgzHa";
    let required_capacity = decode::calculate_decoded_len(input).unwrap();
    let mut output = Vec::with_capacity(required_capacity);

    let bytes_written = decode::decode_into(input, output.spare_capacity_mut())?;
    unsafe {
        output.set_len(bytes_written);
    }
    assert_eq!(output, b"Hello, world!");
    Ok(())
}