Skip to main content

hex_decode_with_case

Function hex_decode_with_case 

Source
pub fn hex_decode_with_case<'a>(
    src: &[u8],
    dst: &'a mut [u8],
    check_case: CheckCase,
) -> Result<&'a mut [u8], Error>
Expand description

Decodes all of src into dst using an explicit letter-case policy.

The size, borrowing and destination-preservation guarantees are identical to hex_decode. Digits are accepted under every policy; CheckCase::None also accepts mixed-case letters. No allocation is performed.

§Errors

Returns the same errors in the same order as hex_decode. A letter rejected by check_case is an Error::InvalidChar, with its byte and zero-based position in src. The first invalid byte wins, including when it is a case violation before another non-hex byte. The entire destination remains unchanged.

§Examples

use faster_hex::{hex_decode_with_case, CheckCase, Error};

let mut bytes = [0; 2];
hex_decode_with_case(b"ab01", &mut bytes, CheckCase::Lower)?;
assert_eq!(bytes, [0xab, 1]);
assert!(matches!(hex_decode_with_case(b"Ab01", &mut bytes, CheckCase::Lower),
    Err(Error::InvalidChar { index: 0, byte: b'A', .. })));
assert_eq!(bytes, [0xab, 1]);