pub fn truncate_utf8(s: &str, max: usize) -> &strExpand description
Truncate s to at most max bytes, landing on a valid UTF-8 character boundary.
Unlike naive &s[..max] this avoids splitting multi-byte characters (emoji, CJK).
§Arguments
s- The string slice to truncate.max- Maximum byte length. Ifmaxexceedss.len(), the entire string is returned unchanged.
§Returns
A subslice of s that is at most max bytes long and ends on a valid UTF-8 character boundary.
§Panics
Does not panic — uses str::floor_char_boundary internally which clamps safely.