]> git.lizzy.rs Git - rust.git/blob - src/docs/struct_excessive_bools.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / struct_excessive_bools.txt
1 ### What it does
2 Checks for excessive
3 use of bools in structs.
4
5 ### Why is this bad?
6 Excessive bools in a struct
7 is often a sign that it's used as a state machine,
8 which is much better implemented as an enum.
9 If it's not the case, excessive bools usually benefit
10 from refactoring into two-variant enums for better
11 readability and API.
12
13 ### Example
14 ```
15 struct S {
16     is_pending: bool,
17     is_processing: bool,
18     is_finished: bool,
19 }
20 ```
21
22 Use instead:
23 ```
24 enum S {
25     Pending,
26     Processing,
27     Finished,
28 }
29 ```