Given the string s, and the index i which is where the 好 character starts:
let s = "abc 好 def";
let i = 4;
What's the best way to get the index after that character, so that I can slice the string and get abc 好? In code:
let end = find_end(s, i);
assert_eq!("abc 好", &s[0..end]);
(Note, + 1 doesn't work because that assumes that the character is only 1 byte long.)
I currently have the following:
fn find_end(s: &str, i: usize) -> usize {
i + s[i..].chars().next().unwrap().len_utf8()
}
But I'm wondering if I'm missing something and there's a better way?