1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-07-05 06:00:30 +02:00

Simpler character counting (#1419)

`str.chars().map(|_| 1).sum()` is just `str.chars().count()`.
This commit is contained in:
Chayim Refael Friedman
2023-10-23 23:36:26 +03:00
committed by GitHub
parent ecd2bc863e
commit 3ba21370bb

View File

@ -23,6 +23,6 @@ fn main() {
} }
fn count_chars(s: &str) -> usize { fn count_chars(s: &str) -> usize {
s.chars().map(|_| 1).sum() s.chars().count()
} }
``` ```