Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solana-account-decoder types don't implement Clone #1357

Open
sam0x17 opened this issue May 14, 2024 · 3 comments
Open

solana-account-decoder types don't implement Clone #1357

sam0x17 opened this issue May 14, 2024 · 3 comments

Comments

@sam0x17
Copy link

sam0x17 commented May 14, 2024

Problem

For exchanges and other consumers of the solana-account-decoder crate types who use them outside of the footprint of this repo, it is super inconvenient that most of these types do not implement Clone (and/or Copy when appropriate). Right now in our footprint we work around this by painstakingly implementing Clone on wrapper types for the majority of types in the crate. These wrapper types are tricky to maintain and are highly sensitive to breaking changes in the form of new/changed struct fields.

Proposed Solution

I will happily go through and derive Clone and/or Copy where appropriate throughout this crate, I just don't want to take the time to do that unless there is consensus that this should be done.

If Copy is contentious, how about just Clone?

@joncinque
Copy link

I don't see any reason why Clone would cause issues -- feel free to submit a PR adding it to the types that you care about!

@sam0x17
Copy link
Author

sam0x17 commented May 23, 2024

In our case this was in a serde serialize/deserialize flow using bincode's codec features, the TLDR being you end up in a situation where you have to take ownership to produce the serialization because of how codec works, but because there is effectively no way to duplicate these solana types (other than a very inefficient extra serialize => deserialize flow just to get the original back), the only remaining option becomes "implement a custom Klone trait on all the types" which is what we actually did in the end 😆

the lesson though is it's pretty reasonable to expect people will always want some way of cloning your public types for various reasons and Rust's orphan rule effectively makes this your responsibility as a library maintainer, for better or for worse

@sam0x17
Copy link
Author

sam0x17 commented May 23, 2024

I'll definitely submit a PR soon when I have a moment :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants