Skip to main content

truncate_with_ellipsis

Function truncate_with_ellipsis 

Source
pub fn truncate_with_ellipsis(s: &str, max_cols: usize) -> String
Expand description

Truncate s to max_cols display columns, appending when truncation happened so the reader sees a visible “there was more” marker instead of a silent cut mid-word. Reserves 1 column for the ellipsis, so the actual content slice is max_cols - 1 cols wide. Strings that already fit are returned unchanged.