pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Spanwhere
I: Iterator<Item = &'a str>,
Expand description
Computes a prefix that fits in the given width
.
Takes non-breakable elements from iter
, while keeping the string width
under width
(and adding delimiter
between each element).
Given total_text = iter.collect().join(delimiter)
, the result is the
length of the longest prefix of width
or less cells, without breaking
inside an element.
Example:
use unicode_segmentation::UnicodeSegmentation;
let my_text = "blah...";
// This returns the number of bytes for a prefix of `my_text` that
// fits within 5 cells.
prefix(my_text.graphemes(true), 5, "");