Skip to main content

decode_array

Function decode_array 

Source
pub const fn decode_array<const OUT: usize>(
    encoded_data: &[u8],
    alphabet: Alphabet,
) -> Result<[u8; OUT], DecodeError>
Expand description

Decodes a base64 string into a fixed-size array at compile time.

The generic parameter OUT is the output array length. It must be exactly the decoded length of the input or a an error is returned.

ยงExample

const RESULT: Result<[u8; 5], base64::DecodeError> =
    base64::decode_array::<5>(b"aGVsbG8=", base64::Alphabet::Standard);
assert_eq!(RESULT.unwrap(), *b"hello");