A str in rust is an utf8 string, to quote the docs ‘String slices are always valid utf8’. But using get or [] on a str might yield invalid utf8 and panic the program because they use byte indexes not char indexes. WTF @rustlang ?!?
-
-
I am asking from a position of complete ignorance: how hard is it to prevent this from happening? Or is „panicking“ like throwing an exception and can be handled? It sounds like it would terminate the whole program immediately ...
-
Panicking conceptually terminates the thread, you *can* catch panics but only if you control the application. The way to prevent this is to know enough about what you’re doing and UTF-8, or use a non-panicking api (in this case, .get)
- 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.