Description
The docs for std::io::mem
mention that there should be some sort of implementation for strings.
The Reader is straightforward.
For Writer, this is tricky, since one cannot just write arbitrary data to a string, it must be UTF-8. Where should the boundary be drawn? Should individual writes be checked for UTF-8ness? Should the writer instead check validity of the underlying string when it is destructed? Should these operate on a &str
(and thus not be growable), or should they make their own ~str
?
I'm leaning towards a StringWriter that writes to an internal ~[u8]
, with an explicit fn get_string(self) -> Option<~str>
that destroys the writer and returns the string if it is valid, None otherwise. Or, maybe it should be Result<~str, ~[u8]>
, so the buffer could still be handled if desired.