Add comments

This commit is contained in:
Alexandre Bury 2017-03-06 10:38:18 -08:00
parent 30cac851e7
commit 5f5fb4e502

View File

@ -48,12 +48,15 @@ pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Prefix
let delimiter_width = delimiter.width();
let delimiter_len = delimiter.len();
// `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 width = token.width();
if current_width + width > available_width {
false
} else {
// Include the delimiter after this token.
current_width += width;
current_width += delimiter_width;
true
@ -66,6 +69,7 @@ pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Prefix
// but only if the iterator was non empty.
let length = sum.saturating_sub(delimiter_len);
// `current_width` includes a delimiter after the last token
debug_assert!(current_width <= available_width + delimiter_width);
Prefix {