]> git.lizzy.rs Git - rust.git/blob - src/docs/len_without_is_empty.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / len_without_is_empty.txt
1 ### What it does
2 Checks for items that implement `.len()` but not
3 `.is_empty()`.
4
5 ### Why is this bad?
6 It is good custom to have both methods, because for
7 some data structures, asking about the length will be a costly operation,
8 whereas `.is_empty()` can usually answer in constant time. Also it used to
9 lead to false positives on the [`len_zero`](#len_zero) lint – currently that
10 lint will ignore such entities.
11
12 ### Example
13 ```
14 impl X {
15     pub fn len(&self) -> usize {
16         ..
17     }
18 }
19 ```