Function goose::util::truncate_string[][src]

pub fn truncate_string(str_to_truncate: &str, max_length: u64) -> String
Expand description

Truncate strings when they’re too long to display.

If a string is longer than the specified max length, this function removes extra the characters and replaces the last two with a double-period ellipsis.

Example

use goose::util;

// All but 7 characters are truncated, with ".." appended.
assert_eq!(util::truncate_string("this is a long string", 9), "this is..");

// All characters are returned as the string is less than 15 characters long.
assert_eq!(util::truncate_string("shorter string", 15), "shorter string");