]> git.lizzy.rs Git - rust.git/blob - src/docs/fn_params_excessive_bools.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / fn_params_excessive_bools.txt
1 ### What it does
2 Checks for excessive use of
3 bools in function definitions.
4
5 ### Why is this bad?
6 Calls to such functions
7 are confusing and error prone, because it's
8 hard to remember argument order and you have
9 no type system support to back you up. Using
10 two-variant enums instead of bools often makes
11 API easier to use.
12
13 ### Example
14 ```
15 fn f(is_round: bool, is_hot: bool) { ... }
16 ```
17
18 Use instead:
19 ```
20 enum Shape {
21     Round,
22     Spiky,
23 }
24
25 enum Temperature {
26     Hot,
27     IceCold,
28 }
29
30 fn f(shape: Shape, temperature: Temperature) { ... }
31 ```