From 5f5fb4e5024438f400bb647474fddb42f400d034 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 6 Mar 2017 10:38:18 -0800 Subject: [PATCH] Add comments --- src/utils/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 04cec20..a4f9bcf 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -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 {