RS.CLIPPY.STRUCT_EXCESSIVE_BOOLS
Using too many bools in a struct
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: struct_excessive_bools. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for excessive use of bools in structs.
Why is this bad?
Excessive bools in a struct is often a sign that the type is being used to represent a state machine, which is much better implemented as an enum.
The reason an enum is better for state machines over structs is that enums more easily forbid invalid states.
Structs with too many booleans may benefit from refactoring into multi variant enums for better readability and API.
Example
struct S {
is_pending: bool,
is_processing: bool,
is_finished: bool,
}
Use instead:
enum S {
Pending,
Processing,
Finished,
}
Configuration
-
max-struct-bools: The maximum number of bool fields a struct can have(default:
3)