]> git.lizzy.rs Git - rust.git/blob - src/docs/chars_last_cmp.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / chars_last_cmp.txt
1 ### What it does
2 Checks for usage of `_.chars().last()` or
3 `_.chars().next_back()` on a `str` to check if it ends with a given char.
4
5 ### Why is this bad?
6 Readability, this can be written more concisely as
7 `_.ends_with(_)`.
8
9 ### Example
10 ```
11 name.chars().last() == Some('_') || name.chars().next_back() == Some('-');
12 ```
13
14 Use instead:
15 ```
16 name.ends_with('_') || name.ends_with('-');
17 ```