-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add std::io::input
simple input function.
#75435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
02268cc
Update lib.rs
sHaDoW-54 6fac729
Update mod.rs
sHaDoW-54 843c2bf
Update stdio.rs
sHaDoW-54 6c42a62
Update stdio.rs
sHaDoW-54 0fc63d9
Update library/std/src/io/stdio.rs
sHaDoW-54 25dcd97
Update stdio.rs
sHaDoW-54 ebb35f1
Update mod.rs
sHaDoW-54 c601238
Update lib.rs
sHaDoW-54 ac0a700
Update stdio.rs
sHaDoW-54 905716b
Update stdio.rs
sHaDoW-54 561f85f
Update mod.rs
sHaDoW-54 e69e325
Update stdio.rs
sHaDoW-54 03d3b6f
Update stdio.rs
sHaDoW-54 80c2964
Update mod.rs
sHaDoW-54 d58892d
Update stdio.rs
sHaDoW-54 fd4cc45
Update stdio.rs
sHaDoW-54 8f2ca07
Update stdio.rs
sHaDoW-54 ab4fb3e
Update stdio.rs
sHaDoW-54 63feaa7
Update stdio.rs
sHaDoW-54 09d7391
Update stdio.rs
sHaDoW-54 e65a3a9
Update mod.rs
sHaDoW-54 f0571fa
Update stdio.rs
sHaDoW-54 2026394
Update stdio.rs
sHaDoW-54 e79e87b
Update stdio.rs
sHaDoW-54 a45bf3a
Update stdio.rs
sHaDoW-54 a9070fa
Update stdio.rs
sHaDoW-54 7710011
Update stdio.rs
sHaDoW-54 9d7f51f
Update stdio.rs
sHaDoW-54 48f9aba
Update stdio.rs
sHaDoW-54 4d4238e
Update stdio.rs
sHaDoW-54 7ae7275
Update stdio.rs
sHaDoW-54 790b1d1
Update stdio.rs
sHaDoW-54 c49a1ca
Update stdio.rs
sHaDoW-54 4608e07
Update stdio.rs
sHaDoW-54 9b681e3
Merge branch 'master' into master
sHaDoW-54 c571550
Update stdio.rs
sHaDoW-54 9aa7bf8
Update stdio.rs
sHaDoW-54 d9d8b01
Update stdio.rs
sHaDoW-54 45b8a1d
Update stdio.rs
sHaDoW-54 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering
stdin().read_line()
does not drop newlines, shouldn't this function keep those in tact as well? Might be a bit confusing thatstdin().read_line()
gives a line including the newline, andio::read_line()
gives one without the newline.I agree it's probably more useful if it already strips the newline. But I'm worried about the inconsistency between two functions with the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the inconsistency between
stdin().read_line()
andio::read_line()
is concerning, but I think wanting to keep the newline would be in the minority and could be corrected with this snippet of code, perhaps we can avoid confusion by changing the name of the function?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that unconditionally adds a
\r\n
or\n
. The original line might or might not end in a newline (e.g. at the end of the stream/file), and might be just a\n
on Windows in certain circumstances. This is why the already existingread_line
function keeps the newlines, to not throw away any information.Anyway, I agree that a function that gives a line with the newline stripped is useful. But considering the existing
read_line
keeps the newlines, this shouldn't have different behaviour while using the same name. (Also, the existingread_line
returnsOk
for zero bytes of input, while this function returns anErr
in that case.)Is there an RFC for this? It's a bit hard right now to keep track of all the design decisions like the name, newline stripping, the possibility of parsing things, showing a prompt or not, etc. Combined with the previous PR, this has now had 108 commits/versions. Maybe it's better to first agree on the interface/api before implementing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good plan, i believe it was mentioned in the previous PR that there have been RFC's on this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better choice may be to change the naming to reflect that it does not include the new lines, at least that could solve the problem with naming inconsistency.
But if we keep the line, then people would need to fallback to
trim
which currently does not return aString
in place but&str
.