arkworks-rs / crypto-primitives

Interfaces and implementations of cryptographic primitives, along with R1CS constraints for them
https://www.arkworks.rs
Apache License 2.0
175 stars 86 forks source link

Fix `Clone` for Merkle Tree Path #65

Closed tsunrise closed 3 years ago

tsunrise commented 3 years ago

Description

The derive of Clone trait for Path<P> doesn't work well, because it implicitly adds a trait bound P: Copy. In most cases, when cloneing a path, user might encounter the following compile error:

the following trait bounds were not satisfied:
            `P: Clone`
            which is required by `ark_crypto_primitives::Path<P>: Clone`

This PR removes the derive and implements Clone trait manually using Derivative instead. Also added Clone for constraint path.


Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why.

weikengchen commented 3 years ago

I used derivative instead. Does that work for the application (I assume LDT)?

tsunrise commented 3 years ago

I used derivative instead. Does that work for the application (I assume LDT)?

Yes it works! Wow derivative is great. I'm going to learn how to use it

weikengchen commented 3 years ago

Derivative indeed is no magic. Just a macro that writes the code that we manually implemented Clone with.

tsunrise commented 3 years ago

Derivative indeed is no magic. Just a macro that writes the code that we manually implemented Clone with.

haha quite handy. The change looks good to me. Feel free to merge