Skip to content

io: code examples, un-xfail conditions tutorial #11271

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
wants to merge 2 commits into from

Conversation

adrientetar
Copy link
Contributor

No description provided.

@@ -499,8 +499,8 @@ pub trait Reader {
/// # Example
///
/// let mut reader = BufferedReader::new(File::open(&Path::new("foo.txt")));
/// for line in reader.lines() {
/// println(line);
/// while !reader.eof() {
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove the for loop? That is more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous example is also from me but:

  • it's a dupe of an example at the beginning of the file
  • the documented function is .eof(), not .lines()

Copy link
Member

Choose a reason for hiding this comment

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

Oh... I'd personally prefer something very simple like:

let mut reader = ...;
println(reader.read_line());

if reader.eof() { println("only one line"); }

rather than encouraging the use of .eof() in places where there are better alternatives.

bors added a commit that referenced this pull request Jan 2, 2014
/// # let _g = ::std::io::ignore_io_error();
///
/// let mut bytes = [0, .. 10];
/// stdin().read(bytes);
Copy link
Member

Choose a reason for hiding this comment

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

Probably best to do

use std::io;
let mut reader = io::stdin(); 

let mut bytes = [0, .. 10];
reader.read(..); 
if reader.eof() { println("..."); }

rather than call stdin() twice. (Since most other readers won't return the same instance if you create them twice; i.e. each File::open(path) creates a new file reader handle.)

bors added a commit that referenced this pull request Jan 4, 2014
@bors bors closed this Jan 4, 2014
@adrientetar adrientetar deleted the patch-io branch January 4, 2014 15:40
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.

3 participants