LINUX.ORG.RU

История изменений

Исправление tp_for_my_bunghole, (текущая версия) :

UTF-8

Rust

let hello = "здравствуйте";

let s1 = &hello[0..4]; // "зд", один нелатинский символ 2 байта

let s2 = &hello[0..1]; // Rust panics at runtime

// ... byte index 1 is not a char boundary ...

You should use ranges to create string slices with caution, because doing so can crash your program.

Go

s := "здравствуйте"
fmt.Println(s[:4]) // "зд"
fmt.Println(s[:1]) // \320

Исходная версия tp_for_my_bunghole, :

UTF-8

Rust

let hello = "Здравствуйте";

let s1 = &hello[0..4]; // "зд", один нелатинский символ 2 байта

let s2 = &hello[0..1]; // Rust panics at runtime

// ... byte index 1 is not a char boundary ...

You should use ranges to create string slices with caution, because doing so can crash your program.

Go

s := "здравствуйте"
fmt.Println(s[:4]) // "зд"
fmt.Println(s[:1]) // \320