Closed
Description
What it does
Calling .iter().cloned.last()
involved doing unnecessary work.
It's better to write it as .iter().last().cloned()
Same thing can rule can be applied to:
.iter().cloned().next()
.iter().cloned().count()
.iter().cloned().flatten()
.iter().cloned().take(...)
.iter().cloned().skip(...)
.iter().cloned().nth(...)
Lint Name
cloned_last
Category
style, perf
Advantage
- More efficient code
Drawbacks
- I don't see any
Example
let _: Option<String> = vec!["1".to_string(), "2".to_string(), "3".to_string()]
.iter().cloned().last()
Could be written as:
let _: Option<String> = vec!["1".to_string(), "2".to_string(), "3".to_string()]
.iter().last().cloned()