-
Notifications
You must be signed in to change notification settings - Fork 119
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
Nonstandard StrConsumer
trait
#275
Comments
On second thought, both options would be breaking, but |
The two traits do bear a superficial similarity, but they do have a different intent to communicate for the user: I doubt a breaking change in this specific case is likely to affect much (any) calling code, so I'm not very concerned about that aspect, but I still prefer an explicit user choice for the purposes of confirming the user's intent to avoid accidentally using a type in an unexpected way. This could be done by making an adapter struct |
On the other hand, because there is only really one way that a Write could implement StrConsumer, maybe it is better to just do the blanket impl. Hmm... Competing priorities is what makes API design interesting. |
I don't really see the difference in intent. Both represent types which can consume UTF-8 encoded bytes, while
I am unsure how this could be misused. I expect base64 to be valid string anyway. Before I discovered that this is even a thing, I created something similar here a went to see if there is an optimised version. |
To be honest, I would be for merging these two write Also, can base64 not be valid UTF-8? I saw the docs and wondered, why the perf hit? Because if it is, there is no need to use checked |
This library doesn't use unsafe, so we have to pay the cost. Fortunately the validation is pretty fast. |
They serve different goals. One produces bytes, the other produces str/String. |
Unfortunately fmt::Write::write_str() returns Result, but StrConsumer::consume() is infallible, so there's not a safe way adapt a Write to a StrConsumer. Can you explain more details about your use case? Maybe there's another way to provide an ergonomic solution. |
It doesn't produce strings internally? If not, then there is no reason to add unsafe. |
The docs considered string formatting as infallible, apart from |
I still don't get it, string is just UTF-8 encoded bytes, which I would expect is what base64 yields. So for me the difference is whether the consumer cares about that or not. |
Sure, go ahead, thanks. |
🤔 Perhaps we could provide an adapter struct that makes it clear that it will panic on fmt::Error, so that while it's not automatic, it's at least not something users have to write themselves. |
So I sent my first try, hope it makes sense. |
Hello, could you please review my changes? |
I'll get to it when I can, just been busy. |
Hello. I was looking at
base64::write::EncoderStringWriter
, which requiresStrConsumer
. However, it is only implemented forString
while looking basically ascore::fmt::Write
.Could I either provide blanket
impl<W: Write> StrConsumer for W
(which shouldn't be breaking) or rip it out and switch toWrite
trait directly (breaking)?The text was updated successfully, but these errors were encountered: