pub fn encode_engine_slice<E: Engine, T: AsRef<[u8]>>(
    input: T,
    output_buf: &mut [u8],
    engine: &E
) -> usize
Expand description

Encode arbitrary octets as base64. Writes into the supplied output buffer.

This is useful if you wish to avoid allocation entirely (e.g. encoding into a stack-resident or statically-allocated buffer).

Panics

If output is too small to hold the encoded version of input, a panic will result.

Example

let s = b"hello internet!";
let mut buf = Vec::new();
// make sure we'll have a slice big enough for base64 + padding
buf.resize(s.len() * 4 / 3 + 4, 0);

let bytes_written = base64::encode_engine_slice(
    s,
    &mut buf,
    &base64::engine::DEFAULT_ENGINE);

// shorten our vec down to just what was written
buf.truncate(bytes_written);

assert_eq!(s, base64::decode(&buf).unwrap().as_slice());