#detect-target #macro-rules #size #compile-time #heuristics #cryptography

cpubits

Compile-time detection heuristics for the optimal word size to use for the target CPU, which in some cases may differ from its address size a.k.a. target_pointer_width. Implemented as macro_rules!

10 releases

Uses new Rust 2024

0.1.0 Feb 3, 2026
0.1.0-rc.3 Feb 2, 2026
0.1.0-rc.1 Jan 23, 2026

#135 in Rust patterns

Download history 2596/week @ 2026-01-22 12984/week @ 2026-01-29 22628/week @ 2026-02-05 30190/week @ 2026-02-12 28090/week @ 2026-02-19

94,737 downloads per month

MIT/Apache

19KB
236 lines

RustCrypto: CPU bits selection

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Compile-time detection heuristics for the optimal word size to use for the target CPU, which in some cases may differ from its address size a.k.a. target_pointer_width.

Implemented as macro_rules!.

Documentation

Example

Below is a basic example of how you can use the cpubits! macro:

cpubits::cpubits! {
    16 => { pub type Word = u16; }
    32 => { pub type Word = u32; }
    64 => { pub type Word = u64; }
}

License

Licensed under either of:

at your option.

Includes portions from the cfg-if crate, which are also dual-licensed Apache 2.0 + MIT. Copyright (c) 2014 Alex Crichton.

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.

No runtime deps