Skip to main content

truncate

Function truncate 

Source
pub fn truncate(s: &str, max_cols: impl Into<usize>) -> &str
Expand description

Truncate s so its display width is at most max_cols terminal columns.

Truncates on a whole-character boundary; a character that would push the total over max_cols is dropped along with the rest of the string. A thin wrapper over retroglyph_core::text::split_at_width; max_cols is saturated to u16::MAX before splitting, matching that function’s own saturation.

Returns a borrowed slice of s, so this allocates nothing. See truncate_owned if you need an owned String (e.g. to store past the lifetime of s).

max_cols takes impl Into<usize> so a Rect dimension (u16) can be passed directly, alongside a plain usize.