1#![doc = include_str!("../docs.md")]
2#![cfg_attr(not(test), no_std)]
3#![cfg_attr(feature = "nightly", feature(const_trait_impl))]
4#![cfg_attr(all(doc, feature = "nightly"), feature(doc_cfg))]
5#![cfg_attr(all(any(doc, test), feature = "nightly"), feature(trivial_bounds))]
6#![warn(clippy::all)]
7#![cfg_attr(
8 all(any(doc, test), feature = "gce"),
9 feature(generic_const_exprs),
10 expect(incomplete_features)
11)]
12
13#[cfg(not(feature = "nightly"))]
14macro_rules! const_trait {
15 ($trait: item) => {
16 $trait
17 };
18}
19
20#[cfg(feature = "nightly")]
21macro_rules! const_trait {
22 (
23 $(#[$attr:meta])*
24 $vis:vis trait $($tokens:tt)*
25 ) => {
26 $(#[$attr])*
27 $vis const trait $($tokens)*
28 };
29}
30
31#[doc(hidden)]
32pub mod __private {
33 pub use static_assertions;
34
35 #[inline(always)]
36 pub const fn min(a: usize, b: usize) -> usize {
37 if a < b {
38 a
39 } else {
40 b
41 }
42 }
43
44 #[inline(always)]
45 pub const fn max(a: usize, b: usize) -> usize {
46 if a > b {
47 a
48 } else {
49 b
50 }
51 }
52
53 #[cfg(feature = "gce")]
54 const_trait! {
55 pub trait NestedBitfield<'a, S> {
56 fn __from_storage(storage: &'a S) -> Self;
57 }
58 }
59
60 #[cfg(feature = "gce")]
61 const_trait! {
62 pub trait NestedMutBitfield<'a, S> {
63 fn __from_storage(storage: &'a mut S) -> Self;
64 }
65 }
66
67 #[cfg(feature = "gce")]
68 const_trait! {
69 pub trait NestedWriteBitfield<'a, S> {
70 fn __from_storage(storage: &'a mut S) -> Self;
71 }
72 }
73}
74
75#[doc = include_str!("../usage_examples/bitfield.md")]
77pub use macros::bitfield;
78
79#[doc = include_str!("../usage_examples/bits.md")]
81pub use macros::bits;
82
83#[doc = include_str!("../usage_examples/with_bits.md")]
85pub use macros::with_bits;
86
87#[doc = include_str!("../usage_examples/set_bits.md")]
89pub use macros::set_bits;
90
91#[doc = include_str!("../usage_examples/conv_raw.md")]
94pub use macros::ConvRaw;
95
96#[cfg(feature = "nightly")]
97#[cfg_attr(all(doc, feature = "nightly"), doc(cfg(feature = "nightly")))]
98#[doc = include_str!("../usage_examples/unwrap_bits.md")]
101pub use macros::UnwrapBits;
102
103mod conv;
104pub use conv::*;
105mod traits;
106pub use traits::*;
107
108#[cfg(any(test, doc))]
109extern crate self as proc_bitfield;
110
111#[cfg(doc)]
112pub mod example;