Skip to content

Commit f3dfe51

Browse files
authored
hex-literal: remove support for comments inside literals and migrate to CTFE (#816)
1 parent c1e32c5 commit f3dfe51

File tree

7 files changed

+163
-413
lines changed

7 files changed

+163
-413
lines changed

.github/workflows/hex-literal.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
rust:
25-
- 1.45.0 # MSRV
25+
- 1.57.0 # MSRV
2626
- stable
2727
target:
2828
- thumbv7em-none-eabi
@@ -48,7 +48,7 @@ jobs:
4848
strategy:
4949
matrix:
5050
rust:
51-
- 1.45.0 # MSRV
51+
- 1.57.0 # MSRV
5252
- stable
5353
steps:
5454
- uses: actions/checkout@v3

hex-literal/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## UNRELEASED
8+
### Changed
9+
- Disallow comments inside hex strings ([#816])
10+
- Migrate to 2021 edition and bump MSRV to 1.57 ([#816])
11+
- Use CTFE instead of proc macro ([#816])
12+
13+
[#816]: https://github.com/RustCrypto/utils/pull/816
14+
715
## 0.3.4 (2021-11-11)
816
### Changed
917
- Provide more info in `panic!` messages ([#664])

hex-literal/Cargo.toml

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ name = "hex-literal"
33
version = "0.3.4"
44
authors = ["RustCrypto Developers"]
55
license = "MIT OR Apache-2.0"
6-
description = "Procedural macro for converting hexadecimal string to byte array at compile time."
6+
description = "Macro for converting hexadecimal string to a byte array at compile time"
77
documentation = "https://docs.rs/hex-literal"
88
repository = "https://github.com/RustCrypto/utils"
9-
keywords = ["hex", "proc-macro", "literals"]
10-
edition = "2018"
11-
12-
[lib]
13-
proc-macro = true
9+
keywords = ["hex", "literals"]
10+
edition = "2021"
11+
rust-version = "1.57"

hex-literal/README.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# [RustCrypto]: hex-literal
2+
3+
[![Crate][crate-image]][crate-link]
4+
[![Docs][docs-image]][docs-link]
5+
![Apache 2.0/MIT Licensed][license-image]
6+
![MSRV][rustc-image]
7+
[![Build Status][build-image]][build-link]
8+
9+
This crate provides the `hex!` macro for converting hexadecimal string literals to a byte array at compile time.
10+
11+
It accepts the following characters in the input string:
12+
13+
- `'0'...'9'`, `'a'...'f'`, `'A'...'F'` — hex characters which will be used in construction of the output byte array
14+
- `' '`, `'\r'`, `'\n'`, `'\t'` — formatting characters which will be ignored
15+
16+
# Examples
17+
```rust
18+
use hex_literal::hex;
19+
20+
// The macro can be used in const contexts
21+
const DATA: [u8; 4] = hex!("01020304");
22+
assert_eq!(DATA, [1, 2, 3, 4]);
23+
24+
// Both upper and lower hex values are supported
25+
assert_eq!(hex!("a1 b2 c3 d4"), [0xA1, 0xB2, 0xC3, 0xD4]);
26+
assert_eq!(hex!("E5 E6 90 92"), [0xE5, 0xE6, 0x90, 0x92]);
27+
assert_eq!(hex!("0a0B 0C0d"), [10, 11, 12, 13]);
28+
29+
// Multi-line literals
30+
let bytes1 = hex!("
31+
00010203 04050607
32+
08090a0b 0c0d0e0f
33+
");
34+
assert_eq!(bytes1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
35+
36+
// It's possible to use several literals (results will be concatenated)
37+
let bytes2 = hex!(
38+
"00010203 04050607" // first half
39+
"08090a0b" /* block comment */ "0c0d0e0f" // second half
40+
);
41+
assert_eq!(bytes1, bytes2);
42+
```
43+
44+
Using an unsupported character inside literals will result in a compilation error:
45+
```rust,compile_fail
46+
# use hex_literal::hex;
47+
hex!("АА"); // Cyrillic "А"
48+
hex!("11 22"); // Japanese space
49+
hex!("0123 // Сomments inside literals are not supported");
50+
```
51+
52+
## Minimum Supported Rust Version
53+
54+
Rust **1.57** or newer.
55+
56+
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.
57+
58+
## License
59+
60+
Licensed under either of:
61+
62+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
63+
* [MIT license](http://opensource.org/licenses/MIT)
64+
65+
at your option.
66+
67+
### Contribution
68+
69+
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.
70+
71+
[//]: # (badges)
72+
73+
[crate-image]: https://img.shields.io/crates/v/hex-literal.svg
74+
[crate-link]: https://crates.io/crates/hex-literal
75+
[docs-image]: https://docs.rs/hex-literal/badge.svg
76+
[docs-link]: https://docs.rs/hex-literal/
77+
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
78+
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
79+
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/hex-literal.yml/badge.svg
80+
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/hex-literal.yml
81+
82+
[//]: # (general links)
83+
84+
[RustCrypto]: https://github.com/RustCrypto

hex-literal/src/comments.rs

-216
This file was deleted.

0 commit comments

Comments
 (0)