RustCrypto: hex-literal
This crate provides the hex! macro for converting hexadecimal string literals to a 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
use hex;
// The macro can be used in const contexts
const DATA: = hex!;
assert_eq!;
// Both upper and lower hex values are supported
assert_eq!;
assert_eq!;
assert_eq!;
// Multi-line literals
let bytes1 = hex!;
assert_eq!;
// It's possible to use several literals
// (results will be concatenated)
let bytes2 = hex!;
assert_eq!;
Using an unsupported character inside literals will result in a compilation error:
hex!; // Cyrillic "А"
hex!; // Japanese space
Сomments inside literals are not supported:
hex!;
Each literal must contain an even number of hex characters:
hex!;
Minimum Supported Rust Version
Rust 1.57 or newer.
In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this crate's SemVer guarantees), however when we do it will be accompanied by a minor version bump.
License
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.