expression

Grapheme boundary offsets

Obtain byte offsets of extended grapheme boundaries for a safe preview. These offsets are suitable for slicing the same unchanged input. Expected stdout (not executed): 0:é 3:ش Common mistake: Reusing offsets after editing or normalizing the input.

Formal Syntax & Structure

rust syntaxrust
text.grapheme_indices(true)

Working Example

Example Snippetrust
fn main() {    use unicode_segmentation::UnicodeSegmentation;    let s = "e\u{0301}ش";    for (i, g) in s.grapheme_indices(true) { println!("{i}:{g}"); }}
Rust Reference