Skip to content

std::io: Add .lines() method to Buffer #10856

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

Merged
merged 1 commit into from
Dec 11, 2013
Merged

Conversation

klutzy
Copy link
Contributor

@klutzy klutzy commented Dec 8, 2013

The .lines() method creates an iterator which yields line with trailing '\n'.
(So it is slightly different to StrSlice.lines(); I don't know if it's worth to synchronize them.)

@@ -25,34 +25,42 @@ Some examples of obvious things you might want to do

* Read lines from stdin

for stdin().each_line |line| {
println(line)
let stdin = stdin();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the current (incorrect) display, I think these code snippets need to be either indented more, or wrapped in ~~~ or ``` (whichever one we're supposed to be using).

(Thanks for updating them!)

@klutzy
Copy link
Contributor Author

klutzy commented Dec 9, 2013

Changed Reader.bytes() to take &mut self. Also removed impl<R> Decorator<R> for ByteIterator<R> which becomes not useful.

@klutzy
Copy link
Contributor Author

klutzy commented Dec 9, 2013

Uh, this fails at bench/shootout-k-nucleotide-pipes.rs.

task '<main>' failed at 'Unhandled condition: io_error: io::IoError{kind: EndOfFile, desc: "End of file", detail: None}', /home/lime/stone/rust/src/libstd/condition.rs:131
task 'task '<unnamed>' failed at 'receiving on closed channel', /home/lime/stone/rust/src/libstd/rt/comm.rs:487

Investigating.

@klutzy
Copy link
Contributor Author

klutzy commented Dec 9, 2013

The failure was because .read_line() raised io_error. As @alexcrichton said above, there will be no way to handle error after io_error ceases.
So I decided to change API that .read_line() and .bytes() to ignore any io_error during iteration. This may need some discussion.

@alexcrichton
Copy link
Member

I think that the best modification to the current API as-is is to modify read_until to swallow the EOF. Right now read_to_end swallows an EOF if it sees one, and I think that it's just a bug that read_line => read_until also doesn't swallow the EOF.

@klutzy
Copy link
Contributor Author

klutzy commented Dec 11, 2013

Updated. It means the api semantics will be changed again later, right?
There is also same issue on .bytes() but I just added some docs instead of swallowing EOF in .read_byte() because I don't know if it's good to change.

@alexcrichton
Copy link
Member

needs a rebase, otherwise looks good to me.

@klutzy
Copy link
Contributor Author

klutzy commented Dec 11, 2013

rebased!

@alexcrichton
Copy link
Member

Hm I also just realized that this is 6 commits, could you rebase these into one?

-   `Buffer.lines()` returns `LineIterator` which yields line using
    `.read_line()`.
-   `Reader.bytes()` now takes `&mut self` instead of `self`.
-   `Reader.read_until()` swallows `EndOfFile`. This also affects
    `.read_line()`.
@klutzy
Copy link
Contributor Author

klutzy commented Dec 11, 2013

done.

bors added a commit that referenced this pull request Dec 11, 2013
The `.lines()` method creates an iterator which yields line with trailing '
'.
(So it is slightly different to `StrSlice.lines()`; I don't know if it's worth to synchronize them.)
@bors bors merged commit 5a93d12 into rust-lang:master Dec 11, 2013
@klutzy klutzy deleted the buf-reader-lines branch December 11, 2013 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants