#hex

macro slices

Convert string literals to static unsigned integer slices in compile time

3 unstable releases

0.2.0 Jul 16, 2021
0.1.1 Dec 3, 2019
0.1.0 May 18, 2019

#222 in #hex

Download history 1411/week @ 2024-07-24 1365/week @ 2024-07-31 1083/week @ 2024-08-07 767/week @ 2024-08-14 740/week @ 2024-08-21 901/week @ 2024-08-28 897/week @ 2024-09-04 795/week @ 2024-09-11 772/week @ 2024-09-18 762/week @ 2024-09-25 722/week @ 2024-10-02 580/week @ 2024-10-09 618/week @ 2024-10-16 470/week @ 2024-10-23 750/week @ 2024-10-30 455/week @ 2024-11-06

2,379 downloads per month
Used in 2 crates

Apache-2.0 OR MIT

7KB

Rust-Slices

License GitHub Actions Crate Badge Crate Doc MSRV 1.45.0

Convert string literals to static unsigned integer slices in compile time.

Usage

The input is a hexadecimal string literal with 0x prefix. The size of input should be an even number.

And you can use any number of _ in the string literal to separate it for more readable.

Examples

use slices::u8_slice;

const VAL: &[u8] = u8_slice!("0x_1234_5678_9abc_def0");
const NULL: &[u8] = u8_slice!("0x");

fn main () {
    let val = &[0x12u8, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0];
    assert_eq!(VAL, val);
    assert_eq!(NULL, &[]);
}

Minimum Supported Rust Version

Rust 1.45.0.

License

Licensed under either of Apache License, Version 2.0 or MIT License, at your option.

Dependencies

~1.5MB
~38K SLoC