Function decode_to_buf

Source
pub fn decode_to_buf(hex: &str, dst: &mut [u8]) -> Result<usize, FromHexError>
Expand description

Decode the given hex string and write the corresponding bytes to dst. Returns the number of bytes written to dst on success.

Accepts lower case, upper case, and mixed case hex characters a-f. Strips 0x prefix if present.

Does not allocate or panic.

ยงExample

use hexhex_impl::*;
let input = "1234"; // or "0x1234"
let mut output = [0u8; 4];
assert_eq!(decode_to_buf(input, &mut output).unwrap(), 2);
assert_eq!(&output[..2], &[0x12, 0x34]);