From 36d5aa016ab591f21b3f94c2a10f6123af4f9e46 Mon Sep 17 00:00:00 2001 From: Constantin Berhard Date: Mon, 6 Mar 2017 22:46:16 +0100 Subject: [PATCH] use Iterator::sum() for summing instead of fold --- src/utils/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a4f9bcf..71dc16c 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -51,7 +51,7 @@ pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Prefix // `current_width` is the width of everything // before the next token, including any space. let mut current_width = 0; - let sum = iter.take_while(|token| { + let sum: usize = iter.take_while(|token| { let width = token.width(); if current_width + width > available_width { false @@ -63,7 +63,7 @@ pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Prefix } }) .map(|token| token.len() + delimiter_len) - .fold(0, |a, b| a + b); + .sum(); // We counted delimiter once too many times, // but only if the iterator was non empty.