I would rather see a function like this added to std: decode_utf8 in bstr - Rust
Then you can pretty easily implement whatever semantics you want.
That is also not a bad idea in any case, and also a good option if this isn't seen as fit for std
. I don't think it's a far stretch for std
though, since surface area is fairly minimal and use cases aren't uncommon (e.g., wanting to display a path without � or wanting to retain some information about what characters are invalid)
(I believe it's true you can use
std::str::from_utf8
to actually implement adecode_utf8
function today, but it's pretty awkward.)
That's exactly what I did for our regex wasm thingy, but it's clunky (there's room for cleanup, but I don't think that much). That's what led me to write this up