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 {