docs: update rationale for excessive-bools

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.
This commit is contained in:
Tom 2025-03-04 14:33:57 +00:00 committed by therewillbecode
parent cdc1d9d87a
commit cc6127bce8

View file

@ -15,12 +15,17 @@ declare_clippy_lint! {
/// use of bools in structs.
///
/// ### Why is this bad?
/// Excessive bools in a struct
/// is often a sign that it's used as a state machine,
/// which is much better implemented as an enum.
/// If it's not the case, excessive bools usually benefit
/// from refactoring into two-variant enums for better
/// readability and API.
/// 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
/// ```no_run