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:
parent
cdc1d9d87a
commit
cc6127bce8
1 changed files with 11 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue