hexlit

Crates.iohexlit
lib.rshexlit
version0.5.5
sourcesrc
created_at2020-09-08 05:13:47.754961
updated_at2022-07-10 18:52:58.324261
descriptionA zero-allocation no_std-compatible zero-cost way to convert hex-strings to byte-arrays at compile time.
homepage
repositoryhttps://github.com/inspier/hexlit
max_upload_size
id286018
size12,862
(inspier)

documentation

https://docs.rs/hexlit

README

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]
    );
}
Commit count: 39

cargo fmt