implement Write trait for BytesMut per issue #425#478
implement Write trait for BytesMut per issue #425#478rich-murphey wants to merge 7 commits intotokio-rs:masterfrom
Conversation
|
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