Function base16::decode_buf
source ·
[−]pub fn decode_buf<T: ?Sized + AsRef<[u8]>>(
input: &T,
v: &mut Vec<u8>
) -> Result<usize, DecodeError>
Expand description
Decode bytes from base16, and appends into the provided buffer. Only allocates if the buffer could not fit the data. Returns the number of bytes written.
In the case of an error, the buffer should remain the same size.
Example
let mut result = Vec::new();
assert_eq!(base16::decode_buf(b"4d61646f6b61", &mut result).unwrap(), 6);
assert_eq!(base16::decode_buf(b"486F6D757261", &mut result).unwrap(), 6);
assert_eq!(std::str::from_utf8(&result).unwrap(), "MadokaHomura");
Availability
This function is only available when the alloc
feature is enabled, as it
needs to write to a Vec.