# Function base64::encode_config_slice

source · [−]

    pub fn encode_config_slice<T: AsRef<[u8]>>(
        input: T,
        config: Config,
        output: &mut [u8]
    ) -> 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

    extern crate base64;

    fn main() {
        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_config_slice(s,
                                base64::STANDARD, &mut buf);

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

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