Crates.io | slices |
lib.rs | slices |
version | 0.2.0 |
source | src |
created_at | 2019-05-18 09:01:13.289541 |
updated_at | 2021-07-16 14:40:30.379669 |
description | Convert string literals to static unsigned integer slices in compile time. |
homepage | https://github.com/yangby-cryptape/rust-slices |
repository | https://github.com/yangby-cryptape/rust-slices |
max_upload_size | |
id | 135057 |
size | 18,656 |
Convert string literals to static unsigned integer slices in compile time.
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.
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, &[]);
}
Licensed under either of Apache License, Version 2.0 or MIT License, at your option.