Lines reading inconsistency
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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