What do I have to do to solve a “use of moved value” error?

前端 未结 3 1793
猫巷女王i
猫巷女王i 2020-11-27 18:32

I\'m trying to compute the 10,001st prime in Rust (Project Euler 7), and as a part of this, my method to check whether or not an integer is prime references a vector:

<
3条回答
  •  再見小時候
    2020-11-27 19:05

    You move value of primes to the function vectorIsPrime (BTW Rust use snake_case by convention). You have other options, but the best one is to borrow vector instead of moving it:

    fn vector_is_prime(num: u64, p: &Vec) -> bool { … }
    

    And then passing reference to it:

    vector_is_prime(num, &primes)
    

提交回复
热议问题