Skip to main content

truncate

Function truncate 

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

Safely truncates a string to a UTF-8-safe prefix sized for truncate_owned.

The returned prefix is at most max_bytes - 3 bytes when truncation is needed, reserving space for the ellipsis that truncate_owned appends.

Use truncate_owned if you need the truncated string with an appended ellipsis (...).

ยงExamples

use rskit_util::strings::truncate;
assert_eq!(truncate("hello world", 8), "hello");
assert_eq!(truncate("hello", 10), "hello");
assert_eq!(truncate("๐Ÿฆ€๐Ÿฆ€๐Ÿฆ€๐Ÿฆ€", 8), "๐Ÿฆ€");