0
votes

Git clone my code here: https://github.com/LixurProtocol/Lixur and open the chain.rs file in chain -> src -> chain.rs.

The error I am getting on line 180 and on line 185 is the following:

error[E0382]: use of moved value: `chain`
   --> src/chain.rs:185:26
    |
180 | fn generate_chain_genesis_transactions (chain: Vec<(String, Transaction)>) {
    |                                         ----- move occurs because `chain` has type `Vec<(std::string::String, Transaction)>`, which does not implement the `Copy` trait
...
185 |         make_transaction(chain, keys_one.2, keys_two.2, 0.0, signature.1);
    |                          ^^^^^ value moved here, in previous iteration of loop

Things I have tried (That haven't worked)

  • Removing the make_transaction function out of the loop and copying it three times
  • Using chain.clone(), only shows one transaction in the chain.json file.
  • Trying to see if I could implement the Copy Trait. Impossible to do due to using the String type.
  • Trying to replace the Vec<(std::string::String, Transaction)> type with a struct called Chain, which had those as its parameters and tried to implement Copy, didn't work.

Is there a way to go around this?

Do you understand how move semantics work in Rust? i.e. the difference between fn foo(t: T) and fn foo(t: &T)? The first time you iterate the value has been moved into the make_transaction function, because i) you aren't passing a reference and ii) it doesn't implement Copy. The second time it's no longer available. - corinjg