Skip to content

Commit ac03973

Browse files
committed
Document #[key(bitset)]
1 parent 77fbad7 commit ac03973

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

fixed-map-derive/src/lib.rs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,45 @@ mod unit_variants;
7070

7171
/// Derive to implement the `Key` trait.
7272
///
73-
/// Requires that `fixed_map` is in scope.
74-
///
7573
/// This derive implements the `Key` trait for a given type.
7674
///
77-
/// The `Key` trait is what allows `fixed_map` to set up storage for a type that will be the key in
78-
/// a fixed map.
75+
/// The `Key` trait is what allows `fixed_map` to set up storage for a type that
76+
/// will be the key in a fixed map.
77+
///
78+
/// # Container attributes
79+
///
80+
/// #### `#[key(bitset)]`
81+
///
82+
/// This ensures that backing storage is performed with a bitset when used with
83+
/// a [`Set`].
84+
///
85+
/// ```rust
86+
/// use fixed_map::{Key, Set};
87+
///
88+
/// #[derive(Clone, Copy, Key)]
89+
/// pub enum Regular {
90+
/// First,
91+
/// Second,
92+
/// Third,
93+
/// }
94+
///
95+
///
96+
/// #[derive(Clone, Copy, Key)]
97+
/// #[key(bitset)]
98+
/// pub enum Bits {
99+
/// First,
100+
/// Second,
101+
/// Third,
102+
/// }
103+
///
104+
/// // Normal storage uses an array of booleans:
105+
/// assert_eq!(std::mem::size_of::<Set<Regular>>(), 3);
106+
///
107+
/// // Bitset storage uses a single u8 (or other appropriate type based on size):
108+
/// assert_eq!(std::mem::size_of::<Set<Bits>>(), 1);
109+
/// ```
110+
///
111+
/// # Guide
79112
///
80113
/// Given the following enum:
81114
///

fixed-map-derive/src/unit_variants.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ pub(crate) fn implement(cx: &Ctxt<'_>, opts: &Opts, en: &DataEnum) -> Result<Tok
2525
let entry_impl = impl_entry(cx, &map_storage)?;
2626
let map_storage_impl = impl_map(cx, en, &map_storage, &names)?;
2727

28-
let set_storage_impl = if let Some(span) = opts.bitset {
29-
if !cfg!(fixed_map_experimental) {
30-
cx.span_error(span, "trying to use experimental feature `bitset` without specifying `--cfg fixed_map_experimental`");
31-
return Err(());
32-
}
33-
28+
let set_storage_impl = if opts.bitset.is_some() {
3429
impl_bitset(cx, en, &set_storage)?
3530
} else {
3631
impl_set(cx, en, &set_storage, &names)?

0 commit comments

Comments
 (0)