4 ms·
> a str with invalid UTF-8 may cause UB, it's not unsafe to handle a str and they sure aren't going to put checks everywhere for it Any way I know of for makin
by hcs 2y ago
> a str with invalid UTF-8 may cause UB, it's not unsafe to handle a str and they sure aren't going to put checks everywhere for it
Any way I know of for making a str from bytes is checked or unsafe, even slices (by byte indexes) are checked (panic). Is there a current example that hasn't been fixed at the language level where this invariant can be broken without unsafe?
- jpc0 2y agoIt's not about me parsing or creating a str. It's about the 100 dependencies every rust project has which might hand me a str that wasn't parsed safely. I can avoid UB in my own C++ code too, the fact that the language has UB is a reason I even look at other options from time to time. To find UB in such a fundamental part of safe Rust was truly a surpise to me. It feels like they could have very easily just made it a byte slice and said it's up yo you to validate, instead they decided it has to be valid UTF-8 or it's UB.