Skip to main content

truncate_text

Function truncate_text 

Source
pub fn truncate_text(text: &str, limit: usize) -> String
Expand description

Truncate text to a limit with ellipsis.

Uses character count rather than byte length to avoid panics on UTF-8 text. Truncates at character boundaries and appends “…” when truncation occurs.

§Example

assert_eq!(truncate_text("hello world", 8), "hello...");
assert_eq!(truncate_text("short", 10), "short");