pub fn hex2bin<'a>(
input: &[u8],
output: &'a mut [u8]
) -> Result<&'a mut [u8], ConvertError>
Expand description
Base16 Decoder - Converts a hexadecimal string to it’s binary form.
Example
use binascii::hex2bin;
let mut my_output_buffer = [0u8; 200];
// If `hex2bin` succeedes, the result will be a `slice` of `my_output_buffer` containing the decoded data.
let res = hex2bin("48656C6C6F2C20576F726C6421".as_bytes(), &mut my_output_buffer);
assert_eq!(res.ok().unwrap(), "Hello, World!".as_bytes());
Failures
This function will fail with:
ConvertError::InvalidInputLength
- If theinput
slice’s length is an odd number.ConvertError::InvalidOutputLength
- If theoutput
’s length isn’t at least half ofinput
’s length.ConvertError::InvalidInput
- If theinput
contains characters that are not valid hex digits.