I want to get the first character of a std::str
. The method char_at()
is currently unstable, as is String::slice_chars
.
I have come up with the following, but it seems excessive to get a single character and not use the rest of the vector:
let text = "hello world!";
let char_vec: Vec<char> = text.chars().collect();
let ch = char_vec[0];
See Question&Answers more detail:os