Skip to content

Commit e13fd9e

Browse files
authored
cpubits: shorthand for | and more combinations (#1398)
- Allows omitting the `16` in `16 | 32` - Adds `16` vs `32 | 64` as an option, where `64` can be omitted
1 parent 765e90d commit e13fd9e

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpubits/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cpubits"
3-
version = "0.1.0-pre.0"
3+
version = "0.1.0-pre.1"
44
authors = ["RustCrypto Developers"]
55
license = "MIT OR Apache-2.0"
66
documentation = "https://docs.rs/cpubits"

cpubits/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,53 @@
2525
//! 64 => { pub type Word = u64; }
2626
//! }
2727
//! ```
28+
//!
29+
//! You can also use the shortened form of the above syntax which implicitly promotes 16-bit
30+
//! platforms to 32-bit ones:
31+
//!
32+
//! ```
33+
//! cpubits::cpubits! {
34+
//! 32 => { pub type Word = u32; }
35+
//! 64 => { pub type Word = u64; }
36+
//! }
37+
//! ```
38+
//!
39+
//! 32-bit and 64-bit platforms can also be combined to differentiate them from 16-bit ones, e.g.
40+
//! `16 => { ... }, 32 | 64 => { ... }`, and `32 | 64` can be shortened to just `32` in such a case.
2841
2942
#[macro_export]
3043
macro_rules! cpubits {
44+
(
45+
16 => { $( $tokens16:tt )* }
46+
32 => { $( $tokens32:tt )* }
47+
) => {
48+
$crate::cpubits! {
49+
16 => { $( $tokens16 )* }
50+
32 | 64 => { $( $tokens32 )* }
51+
}
52+
};
53+
54+
(
55+
32 => { $( $tokens32:tt )* }
56+
64 => { $( $tokens64:tt )* }
57+
) => {
58+
$crate::cpubits! {
59+
16 | 32 => { $( $tokens32 )* }
60+
64 => { $( $tokens64 )* }
61+
}
62+
};
63+
64+
(
65+
16 => { $( $tokens16:tt )* }
66+
32 | 64 => { $( $tokens32:tt )* }
67+
) => {
68+
$crate::cpubits! {
69+
16 => { $( $tokens16 )* }
70+
32 => { $( $tokens32 )* }
71+
64 => { $( $tokens32 )* }
72+
}
73+
};
74+
3175
(
3276
16 | 32 => { $( $tokens32:tt )* }
3377
64 => { $( $tokens64:tt )* }

0 commit comments

Comments
 (0)