expression

Grapheme-aware text previews

Limit a display preview by extended grapheme clusters rather than raw bytes. This still does not determine rendered width. Expected stdout (not executed): 👩‍💻 Common mistake: Assuming grapheme count equals columns in a terminal.

Formal Syntax & Structure

rust syntaxrust
text.graphemes(true).take(limit).collect::<String>()

Working Example

Example Snippetrust
fn main() {    use unicode_segmentation::UnicodeSegmentation;    let s = "👩\u{200D}💻Rust";    let preview: String = s.graphemes(true).take(1).collect();    println!("{preview}");}
Rust Reference