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

assert_eq!(
	array_bytes::hex2bytes("0x4c6f7665204a616e6520466f7265766572"),
	Ok(b"Love Jane Forever".to_vec())
);