In Rust, you can use the unicode-segmentation
crate to iterate over Unicode grapheme clusters. Here's how you can do it:
Add the unicode-segmentation
crate to your Cargo.toml
dependencies:
use unicode_segmentation::UnicodeSegmentation;
fn iterate_grapheme_clusters() {
let text = "नमस्ते";
for cluster in text.grapheme_indices(true) {
let (index, grapheme) = cluster;
println!("Index: {}, Grapheme: {}", index, grapheme);
}
for b in text.chars() {
println!("{}",b);
}
}
cargo run