Function decode_to_array

Source
pub fn decode_to_array<T: AsRef<[u8]>, const N: usize>(
    input: T,
) -> Result<[u8; N], FromHexError>
Expand description

Decode a hex string into a fixed-length byte-array.

Only lowercase characters are valid in the input string (e.g. f9b4ca).

§Errors

This function returns an error if the input is not an even number of characters long or contains invalid hex characters, or if the input is not exactly N / 2 bytes long.

§Example

let bytes = lowercase_hex::decode_to_array(b"6b697769").unwrap();
assert_eq!(&bytes, b"kiwi");