Missing implementation of Cursor for a DerefMut of Vec?


#1

I want to use a std::io::Cursor on a Vec<u8> sitting behind a Mutex to gain the Read/Write traits on that Vec. Yet since Read/Write/… are only implemented on Cursor<Vec<u8>> and not on Cursor<T: DerefMut<Target=Vec<u8>>> I do not see any way for me to use it.

I could just copy paste the code the implements Cursor<<Vec<u8>> and just reimplement it, but that seems less than ideal. Shouldn’t Cursor be implemented on DerefMut? Or at least on &mut Vec<u8>>?

Note: Read/Write is implemented on Cursor<&'a mut [u8]> but that, obviously, doesn’t allow the Write impl to actually change the size of the slice making it less than ideal.

edit: Fixed formatting


#2

You might want to edit your post to fix the type names; it’s currently pretty difficult to read.

Implementing Write for Cursor<&mut Vec<u8>> or something like that probably makes sense; please file a bug.


#3

Oh, also, if you want a workaround, std::mem::replace (https://doc.rust-lang.org/nightly/std/mem/fn.replace.html) can be useful if you want to temporarily move a Vec out of a Mutex.


#4

Reported, Thanks for the work around, I haven’t thought of that.