#bit-flags #bool #getter-setter #compact #single #bools

macro bool_to_bitflags

A library to compact multiple bools into a single bitflags field automatically with getters and setters

4 releases

0.1.3 Jun 22, 2024
0.1.2 May 14, 2024
0.1.1 Apr 2, 2024
0.1.0 Jan 3, 2024

#989 in Procedural macros

Download history 268/week @ 2025-05-01 131/week @ 2025-05-08 288/week @ 2025-05-15 197/week @ 2025-05-22 192/week @ 2025-05-29 294/week @ 2025-06-05 132/week @ 2025-06-12 302/week @ 2025-06-19 319/week @ 2025-06-26 299/week @ 2025-07-03 356/week @ 2025-07-10 413/week @ 2025-07-17 395/week @ 2025-07-24 234/week @ 2025-07-31 241/week @ 2025-08-07 161/week @ 2025-08-14

1,090 downloads per month

MIT license

29KB
672 lines

Bool To Bitflags

A library to compact multiple bools into a single bitflags field automatically with getters and setters.

See the documentation on docs.rs.


lib.rs:

bool-to-bitflags

A struct attribute macro to pack structs with multiple boolean fields into efficent byte packing.

This macro will make struct fields of type bool and Option<bool> be packed into a field called __generated_flags.

This field is responsible for storing the packed bits, and should not be messed with manually, other than to initialize as all-false with {StructName}GeneratedFlags::empty() or all-true with {StructName}GeneratedFlags::all().

Arguments

Argument Name Type Default Value Description
getter_prefix String The prefix before getter names
setter_prefix String set_ The prefix before setter names
private_getters bool Field Visibility If true, getters are forced to be crate-private
private_setters bool Field Visibility If true, setters are forced to be crate-private
document_setters bool false If true, field documentation is used for setters, instead of getters
owning_setters bool false If true, setters take self and return self instead of taking &mut self

MSRV

The Minimum Supported Rust Version of this crate is 1.65.

It is considered a breaking change to raise this requirement.

Dependencies

~0.6–1.3MB
~27K SLoC