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

Implement Copy for Coin / Vec<Coin> #77

Closed
maurolacy opened this issue Sep 7, 2020 · 2 comments
Closed

Implement Copy for Coin / Vec<Coin> #77

maurolacy opened this issue Sep 7, 2020 · 2 comments

Comments

@maurolacy
Copy link
Contributor

maurolacy commented Sep 7, 2020

Currently when coins are sent in a message's sent_funds, they need to be cloned in order to be used independently of the containing struct (env / env.message). This makes some code constructs unnatural (or imply extra cloning of the whole structure).

See by example the discussion in #72 (comment) .

Rust errors E0382 / E0505 suggest as an alternative implementing the Copy trait, for the members that need to be accessed independently.

@maurolacy maurolacy changed the title Implemen Copy for Coin / Vec<Coin> Implement Copy for Coin / Vec<Coin> Sep 7, 2020
@ethanfrey
Copy link
Member

I think Copy is for non-heap objects, that have no references. Vec and String can only be Clone not Copy, which Coin and Vec<Coin> already are.

The code was fine, I just forgot that we needed to use it twice.

@maurolacy
Copy link
Contributor Author

maurolacy commented Sep 7, 2020

Fair enough. I think you can always implement you own Copy trait, though. Basically, by recreating all the objects that are pointers / references in your structs. This is what C++ copy constructors / copy-assignment operators do, by the way.

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

No branches or pull requests

2 participants