Would we want Str.fromUtf8Lossy in the standard library?
It would mostly be used for printing bytes. If the bytes contains values that are not printable in utf8 or don't match utf8 in general, they will be replaced with a filler character.
It would match this rust function: https://doc.rust-lang.org/std/string/struct.String.html#method.from_utf8_lossy
I definitely think so, although I wonder if there's a better name
It's called the "replacement character", so how about fromUtf8WithReplacement?
My main issue with WithReplacement is that makes me think of Str.replaceEach. As such, it feels like it should take extra parameters about what to replace or something of that nature.
As such, I think that it would likely make the method less discoverable and more confusing, especially at a glance.
fromUtf8WithFallback?
fromUtf8WithReplacementChar
Ok yeah, those both sound better to me.
I just wanted to clarify, do we want to add Str.fromUtf8Lossy : List U8 -> Str to the builtins?
My understanding is that this will replace anything that can't be represented in a string with the Unicode Replacement Character (U+FFFD) �
Can this be done in pure roc, or does it need to be a low level in zig?
Lol, I created what I thought was a new thread in ideas ... turns out there was one from a previous discussion.
I'm adding an Issue for this
Also, do we want to add Str.fromUtf16WithFallback?
GH Issue to track this https://github.com/roc-lang/roc/issues/7117
Last updated: Jun 16 2026 at 16:19 UTC