near / borsh-rs

Rust implementation of Binary Object Representation Serializer for Hashing
https://borsh.io/
Apache License 2.0
306 stars 67 forks source link

Add struct/enum attr to relax bounds #290

Open kpp opened 5 months ago

kpp commented 5 months ago

Example

https://github.com/penumbra-zone/jmt/blob/9ba90718d36cdf376630fa036b5a54c35447982c/src/types/proof/definition.rs#L514

#[derive(Debug, Serialize, Deserialize, borsh::BorshSerialize, borsh::BorshDeserialize)]
pub struct UpdateMerkleProof<H: SimpleHasher>(Vec<SparseMerkleProof<H>>);

BorshSerialize is implemented for Vec<SparseMerkleProof<H>> for all H. Yes, it is possible to do a #[borsh(bound(deserialize = "", serialize = ""))] trick in this particular case, but for enums its not obvious.

Possible solution

#[borsh(relax = "T")
enum/struct A<T> {
...

Linked issue: https://github.com/penumbra-zone/jmt/issues/113