Function base16::decode_slice
source ·
[−]pub fn decode_slice<T: ?Sized + AsRef<[u8]>>(
input: &T,
out: &mut [u8]
) -> Result<usize, DecodeError>
Expand description
Decode bytes from base16, and write into the provided buffer. Never allocates.
In the case of a decoder error, the output is not specified, but in practice
will remain untouched for an InvalidLength
error, and will contain the
decoded input up to the problem byte in the case of an InvalidByte error.
Panics
Panics if the provided buffer is not large enough for the input.
Example
let msg = "476f6f642072757374206c6962726172696573207573652073696c6c79206578616d706c6573";
let mut buf = [0u8; 1024];
assert_eq!(base16::decode_slice(&msg[..], &mut buf).unwrap(), 38);
assert_eq!(&buf[..38], b"Good rust libraries use silly examples".as_ref());
let msg2 = b"2E20416C736F2C20616E696D65207265666572656e636573";
assert_eq!(base16::decode_slice(&msg2[..], &mut buf[38..]).unwrap(), 24);
assert_eq!(&buf[38..62], b". Also, anime references".as_ref());
Availability
This function is available whether or not the alloc
feature is enabled.