Function base16::encode_config_slice [] [src]

pub fn encode_config_slice<T: ?Sized + AsRef<[u8]>>(
    input: &T,
    cfg: EncConfig,
    dst: &mut [u8]
) -> usize

Write bytes as base16 into the provided output buffer. Never allocates.

This is useful if you wish to avoid allocation entirely (e.g. your destination buffer is on the stack), or control it precisely.

Panics

Panics if the desination buffer is insufficiently large.

Example

// Writing to a statically sized buffer on the stack.
let message = b"Wu-Tang Killa Bees";
let mut buffer = [0u8; 1024];

let wrote = base16::encode_config_slice(message,
                                        base16::EncodeLower,
                                        &mut buffer);

assert_eq!(message.len() * 2, wrote);
assert_eq!(String::from_utf8(buffer[..wrote].into()).unwrap(),
           "57752d54616e67204b696c6c612042656573");

// Appending to an existing buffer is possible too.
let wrote2 = base16::encode_config_slice(b": The Swarm",
                                         base16::EncodeLower,
                                         &mut buffer[wrote..]);
let write_end = wrote + wrote2;
assert_eq!(String::from_utf8(buffer[..write_end].into()).unwrap(),
           "57752d54616e67204b696c6c6120426565733a2054686520537761726d");