array_bytes

Function hex2slice

Source
pub fn hex2slice<H>(hex: H, slice: &mut [u8]) -> Result<&[u8]>
where H: AsRef<[u8]>,
Expand description

AsRef<[u8]> to &[u8].

This function will modify the given slice’s source and return the revised result.

Return error if:

  • length is odd
  • encounter invalid hex ascii
  • mismatched slice size

§Examples

let mut array = [0; 17];

assert_eq!(
	array_bytes::hex2slice("0x4c6f7665204a616e6520466f7265766572", &mut array),
	Ok(b"Love Jane Forever".as_slice())
);
assert_eq!(array, *b"Love Jane Forever");