near / borsh

Binary Object Representation Serializer for Hashing
https://borsh.io/
487 stars 41 forks source link

Read/Write mutable reference in `serialize` and `deserialize_reader` is unnecessary #141

Closed billythedummy closed 10 months ago

billythedummy commented 10 months ago

Currently, the required method for BorshDeserialize has the following signature:

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>;

However, it can be changed to just:

fn deserialize_reader<R: Read>(reader: R) -> Result<Self>;

because Read has a blanket impl for mut references: https://docs.rs/borsh/latest/borsh/io/trait.Read.html#impl-Read-for-%26mut+R

Similarly, BorshSerialize can be changed from

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>;

to

fn serialize<W: Write>(&self, writer: W) -> Result<()>;

because Write has a blanket impl for mut references: https://docs.rs/borsh/latest/borsh/io/trait.Write.html#impl-Write-for-%26mut+W

This will be a breaking change

billythedummy commented 10 months ago

wrong repo, sorry. Moved to: https://github.com/near/borsh-rs/issues/270