Skip to content
This repository has been archived by the owner on May 6, 2018. It is now read-only.

BytesMut lacks a direct implementation of std::io::Write #28

Closed
NeoLegends opened this issue Mar 16, 2017 · 5 comments
Closed

BytesMut lacks a direct implementation of std::io::Write #28

NeoLegends opened this issue Mar 16, 2017 · 5 comments

Comments

@NeoLegends
Copy link

I'm currently using the codec module to implement a framed tansport.

Before the refactoring, the encode-method of the old Codec trait received a Vec<u8> as parameter to serialize the message into. Vec<u8> directly implements std::io::Write which makes it very easy to put any kind of data into it, since most implementations have some way of writing into an instance of Write.

Now the Vec<u8> has been replaced by BytesMut, which lacks a direct implementation of that trait. Write-compatibility is only archievable through into_writer, which consumes the BytesMut. Consuming is not possible, though, because the method only receives the BytesMut by &mut.

Is this desired behavior?

@carllerche
Copy link
Member

into_writer should work because BufMut is also implemented on &mut BytesMut. So you are passing ownership of the ref, not the value.

That being said, unless there is a coherence problem (which I don't think there is) I don't see why BytesMut couldn't impl Writer directly.

@carllerche
Copy link
Member

Could you open an issue in the bytes repo and reference this one?

@NeoLegends
Copy link
Author

NeoLegends commented Mar 17, 2017

into_writer should work because BufMut is also implemented on &mut BytesMut.

Right now it doesn't, unfortunately.

Could you open an issue in the bytes repo and reference this one?

Sure! Thanks for the quick support!

@Ralith
Copy link
Contributor

Ralith commented Mar 17, 2017

Can't you use BufMut::writer? This is working fine for me, for the reasons @carllerche gave. I don't even see an into_writer method.

@NeoLegends
Copy link
Author

Oh man, sorry. You guys are right. I was mislead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants