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

Don't discourage people from using std::fmt::Write #76729

Closed
camelid opened this issue Sep 15, 2020 · 1 comment · Fixed by #76750
Closed

Don't discourage people from using std::fmt::Write #76729

camelid opened this issue Sep 15, 2020 · 1 comment · Fixed by #76750
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-fmt Area: `std::fmt` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented Sep 15, 2020

The docs for std::fmt::Write discourage using it outside of the standard library:

[…] This is similar to the standard library's io::Write trait, but it is only intended for use in libcore.

This trait should generally not be implemented by consumers of the standard library. The write! macro accepts an instance of io::Write, and the io::Write trait is favored over implementing this trait.

Yet it is relatively often that one needs a trait for writing Unicode to a stream. For example, pulldown-cmark has a trait very similar to this one called StrWrite.

When I asked in Zulip, nobody seemed to know why that comment is there.

It would be good to have a standard that every library can use for this.


@rustbot modify labels: A-fmt T-libs T-doc

@rustbot rustbot added A-fmt Area: `std::fmt` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 15, 2020
@joshtriplett
Copy link
Member

@camelid I think there should be a more nuanced explanation there. It seems fine to impl std::fmt::Write if you only want to accept Unicode. If you can accept either raw bytes or Unicode, you should always prefer to implement std::io::Write, which works fine for UTF-8 bytes too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools A-fmt Area: `std::fmt` T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants