binrw icon indicating copy to clipboard operation
binrw copied to clipboard

BinWrite requires writer to be Sized

Open Wesmania opened this issue 2 years ago • 3 comments

There doesn't seem to be any good reason for writer to be sized, since it's just a mutable reference. Without ?Sized, it's impossible to use trait objects with BinWrite.

Wesmania avatar Feb 28 '22 22:02 Wesmania

There doesn't seem to be any good reason for writer to be sized, since it's just a mutable reference. Without ?Sized, it's impossible to use trait objects with BinWrite.

I dug into this and it appears you're right. However dropping from Sized to ?Sized on the writer-related aspects of this causes a boatload of tests to fail that use #[binrw]'s decorator. Implementors using #[binrw] have a self that is both Sized and ?Sized.

dmgolembiowski avatar Mar 07 '22 02:03 dmgolembiowski

@Wesmania can you provide any more information about what you were trying to do? Currently trying to decide whether or not it is worth the pain of changing this since doing so would break every existing user with a custom parser/serialiser function or manual impl of BinRead/BinWrite.

csnover avatar Aug 23 '22 22:08 csnover

I have a simple tool for serializing / deserializing a data format here. From what I remember this was just a convenience thing that would allow easily writing to either a file or standard output and I worked around it anyway.

Wesmania avatar Aug 27 '22 17:08 Wesmania