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

Document convention for using both fmt::Write and io::Write #37472

Merged
merged 1 commit into from
Nov 9, 2016

Conversation

joshtriplett
Copy link
Member

Using a trait's methods (like Write::write_fmt as used in writeln! and other macros) requires importing that trait directly (not just the module containing it). Both fmt::Write and io::Write provide compatible Write::write_fmt methods, and code can use writeln! and other macros on both an object implementing fmt::Write (such as a String) and an object implementing io::Write (such as Stderr). However, importing both Write traits produces an error due to the name conflict.

The convention I've seen renames both of them on import, to FmtWrite and IoWrite respectively. Document that convention in the Rust documentation for write! and writeln!, with examples.

…fmt::Write

Various existing code does this, but the documentation doesn't explain
how to do it.
@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 @brson (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.

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Nov 2, 2016
…teln, r=alexcrichton

Copyediting on documentation for write! and writeln!

Fix various sentence fragments, missing articles, and other grammatical issues in the documentation for write! and writeln!.

Also fix the links (and link names) for common return types.

(Noticed when preparing rust-lang#37472 ; posted separately to avoid mixing the new documentation with copyedits to existing documentation.)
@brson
Copy link
Contributor

brson commented Nov 9, 2016

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 9, 2016

📌 Commit 955829c has been approved by brson

eddyb added a commit to eddyb/rust that referenced this pull request Nov 9, 2016
…, r=brson

Document convention for using both fmt::Write and io::Write

Using a trait's methods (like `Write::write_fmt` as used in `writeln!` and other macros) requires importing that trait directly (not just the module containing it).  Both `fmt::Write` and `io::Write` provide compatible `Write::write_fmt` methods, and code can use `writeln!` and other macros on both an object implementing `fmt::Write` (such as a `String`) and an object implementing `io::Write` (such as `Stderr`).  However, importing both `Write` traits produces an error due to the name conflict.

The convention I've seen renames both of them on import, to `FmtWrite` and `IoWrite` respectively.  Document that convention in the Rust documentation for `write!` and `writeln!`, with examples.
bors added a commit that referenced this pull request Nov 9, 2016
Rollup of 15 pull requests

- Successful merges: #36868, #37134, #37229, #37250, #37370, #37428, #37432, #37472, #37524, #37614, #37622, #37627, #37636, #37644, #37654
- Failed merges: #37463, #37542, #37645
@bors bors merged commit 955829c into rust-lang:master Nov 9, 2016
@joshtriplett joshtriplett deleted the doc-fmt-write-io-write branch July 26, 2017 23:31
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Aug 27, 2022
…mulacrum

Update documentation for `write!` and `writeln!`

rust-lang#37472 added this documentation, but it
needs updating:

- Remove some documentation duplicated between `writeln!` and `write!`
- Update `write!` docs: can now import traits as `_` to avoid conflicts
- Expand example to show how to implement qualified trait names
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 27, 2022
…mulacrum

Update documentation for `write!` and `writeln!`

rust-lang#37472 added this documentation, but it
needs updating:

- Remove some documentation duplicated between `writeln!` and `write!`
- Update `write!` docs: can now import traits as `_` to avoid conflicts
- Expand example to show how to implement qualified trait names
workingjubilee pushed a commit to tcdi/postgrestd that referenced this pull request Sep 15, 2022
Update documentation for `write!` and `writeln!`

rust-lang/rust#37472 added this documentation, but it
needs updating:

- Remove some documentation duplicated between `writeln!` and `write!`
- Update `write!` docs: can now import traits as `_` to avoid conflicts
- Expand example to show how to implement qualified trait names
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