generic-str 0.3.1

Annoyed that Rust has two string types? Well it doesn't any more
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::string_base::StringBase;

// truncate `&StringBase<[u8]>` to length at most equal to `max`
// return `true` if it were truncated, and the new str.
pub(super) fn truncate_to_char_boundary(
    s: &StringBase<[u8]>,
    mut max: usize,
) -> (bool, &StringBase<[u8]>) {
    if max >= s.len() {
        (false, s)
    } else {
        while !s.is_char_boundary(max) {
            max -= 1;
        }
        (true, &s[..max])
    }
}