How to Work with Non-ASCII Text in Rust

Use Rust's built-in UTF-8 String type and the .chars() iterator to safely handle non-ASCII text.

Use the standard String type, which stores UTF-8 encoded text by default, to handle non-ASCII characters safely.

fn main() {
    let hello = String::from("Hello, δΈ–η•Œ!");
    println!("{hello}");
}

When iterating, use .chars() to get Unicode scalar values instead of bytes to avoid splitting characters incorrectly.