Function array_bytes::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 bytes = [0; 17];

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