Skip to content
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

Rewrite io::BufRead doc examples to better demonstrate behaviors. #40642

Merged
merged 1 commit into from
Mar 26, 2017

Conversation

frewsxcv
Copy link
Member

Prior to this commit, most of the BufRead examples used StdinLock to
demonstrate how certain BufRead methods worked. Using StdinLock is
not ideal since:

  • Relying on run-time data means we can't show concrete examples of how
    these methods work up-front. The user is required to run them in order
    to see how they behave.
  • If the user tries to run an example in the playpen, it won't work
    because the playpen doesn't support user input to stdin.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@frewsxcv
Copy link
Member Author

r? @rust-lang/docs

/// let mut buf = vec![];
///
/// // cursor is at 'l'
/// let num_bytes = cursor.read_until(b'-', &mut buf).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of .unwrap() in examples. Could you replace with .expect() please? Or you could even create a function which returns a Result and use ? operator.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we're using a Cursor though, this will never fail. Should I still use expect? If so, what should the text say?

Copy link
Member

Choose a reason for hiding this comment

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

In this case add a comment explaining that Cursor will never fail. Both solutions are fine to me.

/// let mut buf = String::new();
///
/// // cursor is at 'f'
/// let num_bytes = cursor.read_line(&mut buf).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Same.

Prior to this commit, most of the `BufRead` examples used `StdinLock` to
demonstrate how certain `BufRead` methods worked. Using `StdinLock` is
not ideal since:

* Relying on run-time data means we can't show concrete examples of how
  these methods work up-front. The user is required to run them in order
  to see how they behave.
* If the user tries to run an example in the playpen, it won't work
  because the playpen doesn't support user input to stdin.
@frewsxcv frewsxcv dismissed GuillaumeGomez’s stale review March 24, 2017 03:07

Comments have been addressed.

@GuillaumeGomez
Copy link
Member

Great, thanks!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Mar 25, 2017

📌 Commit 8fba638 has been approved by GuillaumeGomez

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 25, 2017
…=GuillaumeGomez

Rewrite `io::BufRead` doc examples to better demonstrate behaviors.

Prior to this commit, most of the `BufRead` examples used `StdinLock` to
demonstrate how certain `BufRead` methods worked. Using `StdinLock` is
not ideal since:

* Relying on run-time data means we can't show concrete examples of how
  these methods work up-front. The user is required to run them in order
  to see how they behave.
* If the user tries to run an example in the playpen, it won't work
  because the playpen doesn't support user input to stdin.
bors added a commit that referenced this pull request Mar 25, 2017
Rollup of 11 pull requests

- Successful merges: #40347, #40501, #40516, #40524, #40540, #40642, #40683, #40764, #40778, #40807, #40809
- Failed merges: #40771
bors added a commit that referenced this pull request Mar 25, 2017
Rollup of 11 pull requests

- Successful merges: #40347, #40501, #40516, #40524, #40540, #40642, #40683, #40764, #40778, #40807, #40809
- Failed merges: #40771
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 25, 2017
…=GuillaumeGomez

Rewrite `io::BufRead` doc examples to better demonstrate behaviors.

Prior to this commit, most of the `BufRead` examples used `StdinLock` to
demonstrate how certain `BufRead` methods worked. Using `StdinLock` is
not ideal since:

* Relying on run-time data means we can't show concrete examples of how
  these methods work up-front. The user is required to run them in order
  to see how they behave.
* If the user tries to run an example in the playpen, it won't work
  because the playpen doesn't support user input to stdin.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Mar 25, 2017
…=GuillaumeGomez

Rewrite `io::BufRead` doc examples to better demonstrate behaviors.

Prior to this commit, most of the `BufRead` examples used `StdinLock` to
demonstrate how certain `BufRead` methods worked. Using `StdinLock` is
not ideal since:

* Relying on run-time data means we can't show concrete examples of how
  these methods work up-front. The user is required to run them in order
  to see how they behave.
* If the user tries to run an example in the playpen, it won't work
  because the playpen doesn't support user input to stdin.
bors added a commit that referenced this pull request Mar 26, 2017
Rollup of 7 pull requests

- Successful merges: #40642, #40734, #40740, #40771, #40807, #40820, #40821
- Failed merges:
@bors bors merged commit 8fba638 into rust-lang:master Mar 26, 2017
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.

6 participants