Skip to content

Commit 78cfe57

Browse files
authored
Use Iterator::sum() instead of fold()
This simplifies the code a tiny bit.
1 parent f444a31 commit 78cfe57

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ extern crate test;
5959
use tables::charwidth as cw;
6060
pub use tables::UNICODE_VERSION;
6161

62-
use core::ops::Add;
63-
6462
mod tables;
6563

6664
#[cfg(test)]
@@ -121,11 +119,11 @@ pub trait UnicodeWidthStr {
121119
impl UnicodeWidthStr for str {
122120
#[inline]
123121
fn width(&self) -> usize {
124-
self.chars().map(|c| cw::width(c, false).unwrap_or(0)).fold(0, Add::add)
122+
self.chars().map(|c| cw::width(c, false).unwrap_or(0)).sum()
125123
}
126124

127125
#[inline]
128126
fn width_cjk(&self) -> usize {
129-
self.chars().map(|c| cw::width(c, true).unwrap_or(0)).fold(0, Add::add)
127+
self.chars().map(|c| cw::width(c, true).unwrap_or(0)).sum()
130128
}
131129
}

0 commit comments

Comments
 (0)