Skip to main content

hex_decode_array_with_case

Function hex_decode_array_with_case 

Source
pub fn hex_decode_array_with_case<const N: usize>(
    src: &[u8],
    check_case: CheckCase,
) -> Result<[u8; N], Error>
Expand description

Decodes exactly N bytes into an array using an explicit letter-case policy.

This has the ownership, exact-length and allocation-free guarantees of hex_decode_array. Only N == 0 accepts empty input.

§Errors

Returns Error::OddLength, Error::LengthMismatch, then Error::InvalidChar in that order. A disallowed letter case is an invalid character. Mismatched lengths count decoded bytes; invalid-character indexes count source bytes.

§Examples

use faster_hex::{hex_decode_array_with_case, CheckCase};

let id = hex_decode_array_with_case::<2>(b"AB01", CheckCase::Upper)?;
assert_eq!(id, [0xab, 1]);
assert!(hex_decode_array_with_case::<2>(b"ab01", CheckCase::Upper).is_err());