]> git.lizzy.rs Git - rust.git/blob - src/docs/bytes_count_to_len.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / bytes_count_to_len.txt
1 ### What it does
2 It checks for `str::bytes().count()` and suggests replacing it with
3 `str::len()`.
4
5 ### Why is this bad?
6 `str::bytes().count()` is longer and may not be as performant as using
7 `str::len()`.
8
9 ### Example
10 ```
11 "hello".bytes().count();
12 String::from("hello").bytes().count();
13 ```
14 Use instead:
15 ```
16 "hello".len();
17 String::from("hello").len();
18 ```