rust-lang / rust-lang/rfcs

Fix BufRead::read_line unconventional behaviour

Open
#2,808 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-input-output T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced read_line tests in src/libstd/io/mod.rs and src/libstd/io/buffered.rs, and compare them with the documented append behavior described in the issue. Done requires a decided, scoped direction among deprecation, improved documentation and tests, or an additional interface; the current issue does not identify one implementation path.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.