Skip to content

Fix BufRead::read_line unconventional behaviour #2808

Open
@bdejean

Description

@bdejean

Hello,

I've read the documentation so I understand that read_line appends into the passed &mut String argument. I don't understand the use case of that behaviour. To circumvent it, one has to write its own little helper function or not forget to .clear() or .truncate(0) before each new call. So read_line's name doesn't match is behaviour because it reads and appends.

I also looked at the tests 1 and 2 for read_line and they don't even verify that append feature because they .truncate(0) between each check.

Would it be possible to deprecate that behaviour ? If not, would it be possible to document the design intent with a sensible use case, add tests for it and think about an additional simpler interface to load a line into a String ?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-input-outputProposals relating to std{in, out, err}.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions