Skip to main content

truncate

Function truncate 

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

Truncate a string to max_len characters.

If the string is longer than max_len, it is cut and ... is appended. max_len must be at least 4 — otherwise the ellipsis itself would not fit.

§Examples

use dotenv_space::utils::string::truncate;
assert_eq!(truncate("hello world", 8), "hello...");
assert_eq!(truncate("hi", 10), "hi");