Function const_decode_to_array

Source
pub const fn const_decode_to_array<const N: usize>(
    input: &[u8],
) -> 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).

Prefer using decode_to_array instead when possible (at runtime), as it is likely to be faster.

§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

const _: () = {
    let bytes = lowercase_hex::const_decode_to_array(b"6b697769");
    assert!(matches!(bytes.as_ref(), Ok(b"kiwi")));
};