rust-lang / rust-lang/rust

Lines reading inconsistency

Open
#121,562 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I think that's quite common use case when you are being provided with either a file or you need to read the content from stdin. But right now there is no common type for the lines from stdin and the lines from the file, so the following code will throw a compile error:

/// Reads lines from a file or stdin
fn readLines(file: &Option<String>) -> Lines<String> {
    if file.is_some() {
        let file = file.as_ref().unwrap();
        let file = File::open(file)?;
        let reader = io::BufReader::new(file);
        return reader.lines();
    } else {
        let stdin = io::stdin();
        let reader = stdin.lock();
        return reader.lines();
    }
}

What would you say about this guys? It does look like a standard library design inconsistency

Contributor guide

Open the contributing guide

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

No source file or test is named; start by reviewing the example and the standard-library APIs that produce lines from files and stdin. Determine whether a common type or API is warranted, then define the expected compatibility and behavior before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
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.