#byte-array #convert-hex #hex #compile-time #literals #zero-allocation #hex-strings

no-std dev hexlit

A zero-allocation no_std-compatible zero-cost way to convert hex-strings to byte-arrays at compile time

13 releases

0.5.5 Jul 10, 2022
0.5.3 Oct 5, 2021
0.5.1 Jul 10, 2021
0.5.0 Mar 25, 2021
0.3.2 Nov 30, 2020

#59 in Value formatting

Download history 876/week @ 2024-03-14 726/week @ 2024-03-21 425/week @ 2024-03-28 453/week @ 2024-04-04 478/week @ 2024-04-11 521/week @ 2024-04-18 680/week @ 2024-04-25 879/week @ 2024-05-02 1030/week @ 2024-05-09 986/week @ 2024-05-16 1009/week @ 2024-05-23 780/week @ 2024-05-30 453/week @ 2024-06-06 695/week @ 2024-06-13 1259/week @ 2024-06-20 560/week @ 2024-06-27

3,051 downloads per month
Used in 13 crates

MIT license

10KB
225 lines

Current Crates.io Version docs-rs MSRV 1.51+

hexlit

A zero-allocation no_std-compatible zero-cost way to convert hex-strings to byte-arrays at compile time.

To add to your Cargo.toml:

hexlit = "0.5.5"

Example

use hexlit::hex;

fn main() {
    const DATA: [u8; 4] = hex!("01020304");
    assert_eq!(DATA, [1, 2, 3, 4]);
    assert_eq!(hex!("0xDEADBEEF"), [0xDE, 0xAD, 0xBE, 0xEF]);
    assert_eq!(hex!("a1b2c3d4"), [0xA1, 0xB2, 0xC3, 0xD4]);
    assert_eq!(hex!("E5 E6 90 92"), [0xE5, 0xE6, 0x90, 0x92]);
    assert_eq!(hex!("0a0B0C0d"), [10, 11, 12, 13]);
    assert_eq!(hex!(1a 0_b 0C 0d), [0x1a, 11, 12, 13]);
    assert_eq!(hex!(0F 03|0B|0C|0d), [15, 3, 11, 12, 13]);
    assert_eq!(hex!(0A-0B-0C-0d), [10, 11, 12, 13]);
    assert_eq!(
        hex!(
            A1 B2
            C3
            D4
        ),
        [0xA1, 0xB2, 0xC3, 0xD4]
    );
}

No runtime deps