Skip to main content

truncate_deterministic

Function truncate_deterministic 

Source
pub fn truncate_deterministic(str: &str, range: Option<Range<usize>>) -> &str
Expand description

Returns a deterministic prefix selected from the string contents.

The candidate index is the wrapping sum of input bytes modulo the byte length, with empty input using a modulus of one. When a range is supplied, the index is clamped inclusively between range.start and range.end; reversed endpoints panic. The index is then interpreted as a character position, or the full string is returned when that position does not exist. Because selection uses byte length but truncation uses character count, non-ASCII input more often falls back to the full string.