Open
Description
Would be nice to have an in-place decode function, i.e.:
fn decode_inplace(data: &mut [u8]) -> Result<usize, DecodeError> { … }
Since output is never longer than input, the decoded value can be saved directly into the input buffer thus possibly saving on having to allocate a new output buffer, e.g.:
fn b64decode(value: String) -> Result<Vec<u8>, base64::DecodeError> {
let mut vec = value.into_bytes();
let new_length = base64::decode_inplace(&mut vec[..])?;
vec.truncate(new_length);
Ok(vec)
}
This would of course come with a caveat that if error is encountered the data in the buffer is in unspecified state (portion of it could have been overwritten).
Metadata
Assignees
Labels
No labels