Skip to content

Commit cee9abf

Browse files
authored
docs: update rationale for excessive-bools (#14351)
Adds the reasoning to the docs for this rule on why enums are generally better for representing state machines than structs with many bool fields. changelog: [struct_excessive_bools]: Improve documentation
2 parents 81643e2 + cc6127b commit cee9abf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

clippy_lints/src/excessive_bools.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ declare_clippy_lint! {
1515
/// use of bools in structs.
1616
///
1717
/// ### Why is this bad?
18-
/// Excessive bools in a struct
19-
/// is often a sign that it's used as a state machine,
20-
/// which is much better implemented as an enum.
21-
/// If it's not the case, excessive bools usually benefit
22-
/// from refactoring into two-variant enums for better
23-
/// readability and API.
18+
/// Excessive bools in a struct is often a sign that
19+
/// the type is being used to represent a state
20+
/// machine, which is much better implemented as an
21+
/// enum.
22+
///
23+
/// The reason an enum is better for state machines
24+
/// over structs is that enums more easily forbid
25+
/// invalid states.
26+
///
27+
/// Structs with too many booleans may benefit from refactoring
28+
/// into multi variant enums for better readability and API.
2429
///
2530
/// ### Example
2631
/// ```no_run

0 commit comments

Comments
 (0)