Strings In Depth14 / 18
Up next

Mind char boundaries

fn main() {
    let s = "caf\u{e9}";
    // 'é' is two bytes; slicing mid-char would panic,
    // so take a prefix by chars instead
    let prefix: String = s.chars().take(3).collect();
    println!("{prefix}");
}
What you're solving

slice on chars for non-ASCII text