harper_core/
char_string.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use smallvec::SmallVec;

/// A char sequence that improves cache locality.
/// Most English words are fewer than 12 characters.
pub type CharString = SmallVec<[char; 12]>;

pub trait CharStringExt {
    fn to_lower(&self) -> CharString;
    fn to_string(&self) -> String;
}

impl CharStringExt for [char] {
    fn to_lower(&self) -> CharString {
        let mut out = CharString::with_capacity(self.len());

        out.extend(self.iter().flat_map(|v| v.to_lowercase()));

        out
    }
    fn to_string(&self) -> String {
        self.iter().collect()
    }
}