const_hex

Function const_check_raw

Source
pub const fn const_check_raw(input: &[u8]) -> bool
Expand description

Returns true if the input is a valid hex string.

Note that this does not check prefixes or length, but just the contents of the string.

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

ยงExamples

const _: () = {
    assert!(const_hex::const_check_raw(b"48656c6c6f20776f726c6421"));

    // Odd length, but valid hex
    assert!(const_hex::const_check_raw(b"48656c6c6f20776f726c642"));

    // Valid hex string, but the prefix is not valid
    assert!(!const_hex::const_check_raw(b"0x48656c6c6f20776f726c6421"));

    assert!(!const_hex::const_check_raw(b"Hello world!"));
};