Skip to main content

hex

Macro hex 

Source
macro_rules! hex {
    ($($s:literal)*) => { ... };
}
Expand description

Converts string literals containing hexadecimal data into a byte array.

Each literal may begin with 0x or 0X; when present, the prefix must be its first two characters. Spaces, tabs, carriage returns, and newlines are ignored. Each literal must contain an even number of hexadecimal digits after its optional prefix and whitespace are removed.

The array length is computed from the same prefix-free literals that are decoded, so the output contains exactly the bytes represented by the input.

ยงExamples

use commonware_formatting::hex;

const BYTES: [u8; 4] = hex!("0x12 34" "0Xab cd");
assert_eq!(BYTES, [0x12, 0x34, 0xab, 0xcd]);