Borrow-checker and move errors while using vectors in loops and functions

by Pandharinath Daspute   Last Updated August 25, 2019 08:26 AM - source

I am new to Rust. I often get stuck by borrow checker and move errors while using vectors in for-loop, while-loop, if-statement and functions.

I read necessary chapters, did some practice and used Rustlings.

I mostly run into following errors when I am using vectors in functions, for-loop, while-loop, and if-statement.

borrow of moved value: `vector1`
cannot find `vector1` in the scope
cannot borrow `vector1` as mutable more than once at a time
cannot borrow `vector1` as mutable because it is also borrowed as immutable

Can you give a concise set of rules or advice for ownership, borrowing and move in rust? How do you avoid/tackle Rust's borrow-checker and move errors while using vectors specially in functions, for-loop, while-loop, and if-statement? Can you refer to some webpage for a good summary, tutorial or code practice?



Related Questions



I can't get ownership of a value out of a function

Updated April 05, 2019 08:26 AM


Overwriting objects in Rust

Updated May 30, 2019 04:26 AM