Skip to main content

prefix_len

Function prefix_len 

Source
pub fn prefix_len(text: &str, width: u16) -> usize
Expand description

The byte offset where the longest prefix of whole clusters that fits in width cells ends.

Slice with it to cut text safely: &text[..prefix_len(text, width)]. A cluster that would cross width stays out whole, so the prefix can be narrower than width. When all of text fits, the offset is text.len().