about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGiles Cope <gilescope@gmail.com>2021-01-26 11:36:02 +0000
committerGiles Cope <gilescope@gmail.com>2021-01-26 11:36:02 +0000
commitc07e5585b312aaa76f7bd35e60cf8e8d9164369c (patch)
tree6d52238e8c1c78a3b4433f1ea0680d83de0726ad
parent425a70a460abac1182a792c6c2af6dff69663c3c (diff)
downloadrust-c07e5585b312aaa76f7bd35e60cf8e8d9164369c.tar.gz
rust-c07e5585b312aaa76f7bd35e60cf8e8d9164369c.zip
Let's try the most idiomatic way.
-rw-r--r--library/core/src/str/iter.rs6
1 files changed, 1 insertions, 5 deletions
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index 34c31d599a3..0c74f6e45a7 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -47,11 +47,7 @@ impl<'a> Iterator for Chars<'a> {
     #[inline]
     fn count(self) -> usize {
         // length in `char` is equal to the number of non-continuation bytes
-        let mut char_count = 0;
-        for &byte in self.iter {
-            char_count += !utf8_is_cont_byte(byte) as usize;
-        }
-        char_count
+        self.iter.map(|&byte| !utf8_is_cont_byte(byte) as usize).sum()
     }
 
     #[inline]