Skip to main content

truncate

Function truncate 

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

Truncate s to at most max characters, appending "..." if truncation occurs.

Truncation is always on a valid UTF-8 character boundary, so the result may be shorter than max for multi-byte inputs.

use rok_utils::string::truncate;
assert_eq!(truncate("hello world", 5), "he...");
assert_eq!(truncate("hi", 10), "hi");