#hex #proc-macro #literals

dev hex-literal

Procedural macro for converting hexadecimal string to byte array at compile time

7 releases

✓ Uses Rust 2018 edition

0.2.1 Aug 24, 2019
0.2.0 Apr 23, 2019
0.1.4 Mar 14, 2019
0.1.3 Feb 22, 2019
0.1.0 Jan 29, 2018

#8 in Procedural macro helpers

Download history 3885/week @ 2019-06-15 3855/week @ 2019-06-22 5881/week @ 2019-06-29 7244/week @ 2019-07-06 7379/week @ 2019-07-13 7317/week @ 2019-07-20 7650/week @ 2019-07-27 8692/week @ 2019-08-03 10211/week @ 2019-08-10 9740/week @ 2019-08-17 11375/week @ 2019-08-24 12191/week @ 2019-08-31 12402/week @ 2019-09-07 13327/week @ 2019-09-14 12434/week @ 2019-09-21

28,381 downloads per month
Used in 72 crates (70 directly)

MIT/Apache

7KB

RustCrypto: utility crates Build Status

This repository contains various utility crates used in the RustCrypto project.

License

All crates licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

This crate provides hex! macro for converting hexadecimal string literal to byte array at compile time.

It accepts the following characters in the input string:

  • '0'...'9', 'a'...'f', 'A'...'F' — hex characters which will be used in construction of the output byte array
  • ' ', '\r', '\n', '\t' — formatting characters which will be ignored

Examples

# #[macro_use] extern crate hex_literal;
const DATA: [u8; 4] = hex!("01020304");

# fn main() {
assert_eq!(DATA, [1, 2, 3, 4]);
assert_eq!(hex!("a1 b2 c3 d4"), [0xA1, 0xB2, 0xC3, 0xD4]);
assert_eq!(hex!("E5 E6 90 92"), [0xE5, 0xE6, 0x90, 0x92]);
assert_eq!(hex!("0a0B 0C0d"), [10, 11, 12, 13]);
let bytes = hex!("
    00010203 04050607
    08090a0b 0c0d0e0f
");
assert_eq!(bytes, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
# }

Dependencies

~0.6–0.9MB
~21K SLoC