blob: b4324bd83990a80d438be00bbef771a6c7a9a912 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
### What it does
Checks for use of `Option<Option<_>>` in function signatures and type
definitions
### Why is this bad?
`Option<_>` represents an optional value. `Option<Option<_>>`
represents an optional optional value which is logically the same thing as an optional
value but has an unneeded extra level of wrapping.
If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases,
consider a custom `enum` instead, with clear names for each case.
### Example
```
fn get_data() -> Option<Option<u32>> {
None
}
```
Better:
```
pub enum Contents {
Data(Vec<u8>), // Was Some(Some(Vec<u8>))
NotYetFetched, // Was Some(None)
None, // Was None
}
fn get_data() -> Contents {
Contents::None
}
```
|