-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add a blanket impl for core::fmt::Write
if there is an impl for std::io::Write
#77733
Comments
This has the potential of causing many panic-by-default implementations, which would happen for virtually any |
What about a Note this could also go the other way ( |
As noted by Lonami, they are not quite describing the same function, and while the #[derive] idea is interesting, observationally derives tend to be pretty conservative, as they rarely make new assertions but rather only are valid if certain requirements are met. It would be desirable to have some kind of meta-abstraction that touches both, but I don't think that is practical in current Rust, I think. |
If we go with the |
Adding a blanket impl is a breaking change because the impl can conflict with downstream impls. |
Hmm, I don't think the opposite would be possible; the opposite would involve more panic-by-default impls since
Hmm, that's unfortunate. Maybe a |
At least it would be nice to have |
An adapter struct might be the way to solve this. There is even a struct already in rust/library/std/src/io/mod.rs Lines 1496 to 1501 in 5ddef54
|
I don't think a blanket impl would make sense anyway, because the two traits are at different levels of abstraction (bytes vs text). The standard library tends to make encoding explicit elsewhere (e.g. |
rust-lang/libs-team#133 is trying to solve this issue, but in the meantime I have a crate which should do the job: https://github.com/SUPERCILEX/io-adapters |
Advantages
Types which implement
std::io::Write
get an implementation ofcore::fmt::Write
for free.core::fmt::Write
is useful if you only want to accept UTF-8 data.Disadvantages
Could it hurt type inference? If so, is there some way of allowing
impl core::fmt::Write for Foo {}
(i.e., empty impl body) if there is an impl forstd::io::Write
?Cc pulldown-cmark/pulldown-cmark#492
The text was updated successfully, but these errors were encountered: