Re:String types in Rust
by derefr on Wednesday March 30, 2016 @06:39PM
(#11393584)
I don't really get the point of it; I'd think that, properly, what you'd want is:
1. a plain "buffer of unparsed octets" type (like Erlang's "binary" type), to hold onto your weird invalid UTF-16 (or whatever other weird invalid stuff you like);
and 2. a strict, validated-on-construction "sequence of codepoints" type.
Going from #1 to #2 wouldn't be a direct cast; it'd instead be a stream-parser function that could be hooked with a callback, which would be handed parsed-and-valid, and invalid-and-left-unparsed, "segments":
...and would then respond with a valid segment, which could just be "" to discard the input segment.
The default callback would presumably respond to a binary() of size N by emitting a "�" string of length N. That's pretty much what we have today, but both sturdier and more extensible.
1. a plain "buffer of unparsed octets" type (like Erlang's "binary" type), to hold onto your weird invalid UTF-16 (or whatever other weird invalid stuff you like);
and 2. a strict, validated-on-construction "sequence of codepoints" type.
Going from #1 to #2 wouldn't be a direct cast; it'd instead be a stream-parser function that could be hooked with a callback, which would be handed parsed-and-valid, and invalid-and-left-unparsed, "segments":
...and would then respond with a valid segment, which could just be "" to discard the input segment.The default callback would presumably respond to a binary() of size N by emitting a "�" string of length N. That's pretty much what we have today, but both sturdier and more extensible.