Skip to content

Add StringReader, StringWriter, and StringStream #10564

Closed
@emberian

Description

@emberian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions