pub unsafe fn decode_into_unchecked(
input: &[u8],
output: &mut [MaybeUninit<u8>],
) -> Result<usize, usize>Expand description
Decode base64-encoded input into the provided slice without validating its length.
On success Result::Ok containing the amount of bytes written is returned.
Otherwise, Result::Err containing the offset of the first invalid input byte is returned.
§Safety
output’s length must be AT LEASTinput.len() * 3 / 4
§Example
use weakauras_codec_base64::decode;
let input = b"ivgBS9glGC3BYXgzHa";
let required_capacity = decode::calculate_decoded_len(input).unwrap();
let mut output = Vec::with_capacity(required_capacity);
// SAFETY:
// - buffer's capacity is enough for storing decoded base64-input;
// - decode_into_unchecked returns the amount of bytes written,
// thus it is safe to call set_len using its return value.
unsafe {
let bytes_written =
decode::decode_into_unchecked(input, output.spare_capacity_mut()).unwrap();
output.set_len(bytes_written);
}
assert_eq!(output, b"Hello, world!");