-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
…fmt::Write Various existing code does this, but the documentation doesn't explain how to do it.
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. |
…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.)
@bors r+ rollup |
📌 Commit 955829c has been approved by |
…, 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.
…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
…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
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
Using a trait's methods (like
Write::write_fmt
as used inwriteln!
and other macros) requires importing that trait directly (not just the module containing it). Bothfmt::Write
andio::Write
provide compatibleWrite::write_fmt
methods, and code can usewriteln!
and other macros on both an object implementingfmt::Write
(such as aString
) and an object implementingio::Write
(such asStderr
). However, importing bothWrite
traits produces an error due to the name conflict.The convention I've seen renames both of them on import, to
FmtWrite
andIoWrite
respectively. Document that convention in the Rust documentation forwrite!
andwriteln!
, with examples.