Code change:
} #[test] <ins> fn test_str_from_utf8_lossy() { let xs = bytes!("hello"); assert_eq!(from_utf8_lossy(xs), ~"hello"); let xs = bytes!("ศไทย中华Việt Nam"); assert_eq!(from_utf8_lossy(xs), ~"ศไทย中华Việt Nam"); let xs = bytes!("Hello", 0xC2, " There", 0xFF, " Goodbye"); assert_eq!(from_utf8_lossy(xs), ~"HellouFFFD ThereuFFFD Goodbye"); let xs = bytes!("Hello", 0xC0, 0x80, " There", 0xE6, 0x83, " Goodbye"); assert_eq!(from_utf8_lossy(xs), ~"HellouFFFDuFFFD ThereuFFFD Goodbye"); let xs = bytes!(0xF5, "foo", 0xF5, 0x80, "bar"); assert_eq!(from_utf8_lossy(xs), ~"uFFFDfoouFFFDuFFFDbar"); let xs = bytes!(0xF1, "foo", 0xF1, 0x80, "bar", 0xF1, 0x80, 0x80, "baz"); assert_eq!(from_utf8_lossy(xs), ~"uFFFDfoouFFFDbaruFFFDbaz"); let xs = bytes!(0xF4, "foo", 0xF4, 0x80, "bar", 0xF4, 0xBF, "baz"); assert_eq!(from_utf8_lossy(xs), ~"uFFFDfoouFFFDbaruFFFDuFFFDbaz"); let xs = bytes!(0xF0, 0x80, 0x80, 0x80, "foo", 0xF0, 0x90, 0x80, 0x80, "bar"); assert_eq!(from_utf8_lossy(xs), ~"uFFFDuFFFDuFFFDuFFFDfooU00010000bar"); // surrogates let xs = bytes!(0xED, 0xA0, 0x80, "foo", 0xED, 0xBF, 0xBF, "bar"); assert_eq!(from_utf8_lossy(xs), ~"uFFFDuFFFDuFFFDfoouFFFDuFFFDuFFFDbar"); } #[test] </ins> fn test_to_send_str() { assert_eq!("abcde".to_send_str(), SendStrStatic("abcde")); assert_eq!("abcde".to_send_str(), SendStrOwned(~"abcde"));

Related discussion:
text: We need some way to interpret a as UTF-8, using the replacement character for invalid sequences instead of conditions. This would ideally be provided in the form of an .
Could we remove the current condition API in favour of this? It doesn't really seem to offer anything but failing, and we already have an API returning an .
I would be quite pleased if we could do that. Using the condition is rather awkward, and I would rather just have replacement chars myself.
This is a duplicate of , no?
And also the e-mail thread here I think is relevant:
This is an implementation of a mostly complete → UTF-8 decoder
It's only a duplicate if the intended resolution of is to use the replacement char instead of conditions, but it's unclear from the discussion if that's the plan.
I guess my thinking was that a maximally expressive condition-based solution would let one express a replacement char approach using conditions. But I don't actually favor doing that at this point. Or at least, I don't favor making that the only way to accomplish this, since I suspect a more specialized approach will be much nicer to use (both in terms of programmer convenience and in terms of efficiency). So okay, this is not a duplicate of .
Rust needs to support both fatal and replacement error handling modes, it should follow the WHATWG spec simonsapin has said (edit by is WHATWG spec.)
the fatal mode is already handled by the API
well, the current functions in str don't handle decoding buffers in chunks like the proposed encodings API. But yes, it does handle one-off decoding with 'fatal' error handling.
I think we need to improve/extend our API along the lines suggested here for 1.0. Nominating for P-backcompat-lang. (Arguably we could avoid the backwards compatibility hazard by offering a fail-only method for 1.0 and then adding an alternative entry point that provides the more flexible API supporting replacement characters in post 1.0. But I think this case is important enough that we should try to get the primary API method to provide both choices up front. That, or put dynamic fluid support in for representing the state of that choice.)
I submitted a PR for this last night, although I forgot there was an open issue too so I didn't link them. The PR is