0xSpaceShard / starknet-devnet-rs

A local testnet for Starknet... in Rust
https://0xspaceshard.github.io/starknet-devnet-rs/
MIT License
104 stars 61 forks source link

removed copy trait from Felt #457

Closed g4titanx closed 4 months ago

g4titanx commented 4 months ago

i opened the PR as suggested. you can see the approach i took in fixing this issue: https://github.com/0xSpaceShard/starknet-devnet-rs/issues/342

g4titanx commented 4 months ago

here i am currently trying to fix this error:

error[E0271]: type mismatch resolving `<Iter<'_, Felt> as IntoIterator>::Item == Felt`
   --> crates/starknet-devnet-types/src/rpc/transactions.rs:693:41
    |
693 |                 calldata_to_hash.extend(v1.constructor_calldata.iter());
    |                                  ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Felt`, found `&Felt`
    |                                  |
    |                                  required by a bound introduced by this call
    |

my first approach to fixing this error was to do this:

                let mut calldata_to_hash: Vec<&Felt> = vec![&v1.class_hash, &v1.contract_address_salt];

now, this fixes this particular error but at the same time, it generates more errors across different crates. here's an example:

error[E0507]: cannot move out of `v3.common.version` which is behind a shared reference
   --> crates/starknet-devnet-types/src/rpc/transactions.rs:880:21
    |
880 |                     v3.common.version,
    |                     ^^^^^^^^^^^^^^^^^ move occurs because `v3.common.version` has type `Felt`, which does not implement the `Copy` trait

now, what do you suggest

g4titanx commented 4 months ago

i have tried a copy of metthods, that was about a week ago. honestly, I cant remember everything I tried. but, I know the one I mentioned was one of the best approach I could come up with.

also, another way I tried was to create a reference through each crate since Felt doesn't implement a copy trait. which led me to creating a lifetime for each of the reference, it was too complemented. oh, it fixed most of the errors but at the end, it was going to increase the compile time and it led to one or two errors i couldn't fix.

how would you fix this?

g4titanx commented 4 months ago

When you remove Copy, it means you'll have to add more .clone()

okay, I would do that. what do you think about the error I mentioned here: https://github.com/0xSpaceShard/starknet-devnet-rs/pull/457#issuecomment-2087977982

marioiordanov commented 4 months ago

IMO solving this issue will require bigger refactoring, either use references or move the variables where needed. Mainly depends on the context of the caller