'Access iterator inside its for loop
I am testing a custom bi-directional iterator in rust but i ran into error
error[E0382]: borrow of moved value: `iter`
--> src/main.rs:40:13
|
37 | let mut iter = BiIterator::from(vec![1, 2, 3]);
| -------- move occurs because `iter` has type `BiIterator<i32>`, which does not implement the `Copy` trait
38 | for i in iter {
| ----
| |
| `iter` moved due to this implicit call to `.into_iter()`
| help: consider borrowing to avoid moving into the for loop: `&iter`
39 | if i == 3 {
40 | iter.position(0);
| ^^^^^^^^^^^^^^^^ value borrowed here after move
|
note: this function takes ownership of the receiver `self`, which moves `iter`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|