-
Notifications
You must be signed in to change notification settings - Fork 288
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
implement Write trait for BytesMut per issue #425 #478
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Could we add some tests? |
Because BufMut already implements fmt::Write, this change will break any code that uses |
Sorry, I missed conflict with fmt::Write.
@sfackler good catch! we should add a test to cover this edge case. |
At the moment, I'm not sure how to proceed. I don't know how to avoid breaking write!() as @sfackler said, but wow, I'm so glad he caught it. |
I don't see a way to proceed with this. It isn't great, but one can always use I would appreciate a test that demonstrates the ability to call |
I think you could in theory add an inherent |
Thanks so much for the directions @sfackler and @carllerche. I'll write some tests so we can evaluate them. |
I tried adding write_fmt() directly on impl BytesMut, and still saw compiler errors when write!() saw both io::Write and fmt::Write impls. So here's another option. This adds a BytesMutExt trait that implements io::Write. It's a bit awkward to use though:. The successful test (included) looks like this:
This works, but it's awkward. I'm not sure this is helpful at all. Please let me know if I've misunderstood the idea of having a write_fmt() directly in And if you think this is a dead horse, that 's ok too. |
Found my way here from the issue. Did you consider something like the following?
I think this is more readable than The problem I have with the current
|
You could do |
Oh, I didn't think of that. Thanks for the tip! Actually, I would have been perfectly happy if that example were just in |
There is some discussion of this in #425.
This implements Write for BytesMut exactly as is done for Vec here:
https://doc.rust-lang.org/src/std/io/impls.rs.html#370-402