Is there any way to deconstruct the array like [a, b] = map
so the two array elements are moved into a
and b
, so that later a
and b
can be moved into another function (like printme
in this case).
enum Direction {
North,
East,
South,
West,
}
struct RoadPoint {
direction: Direction,
index: i32,
}
fn printme(a: RoadPoint, b: RoadPoint) {
println!("First: {}", a.index);
}
fn main() {
let mut map: [RoadPoint; 2] = [
RoadPoint {
direction: Direction::North,
index: 0,
},
RoadPoint {
direction: Direction::North,
index: 0,
},
];
for i in 1..3 {
map[i].index = 10;
}
//move out
printme(map[0], map[1])
}
error[E0508]: cannot move out of type `[RoadPoint; 2]`, a non-copy array
--> src/main.rs:34:13
|
34 | printme(map[0], map[1])
| ^^^^^^ cannot move out of here
error[E0508]: cannot move out of type `[RoadPoint; 2]`, a non-copy array
--> src/main.rs:34:21
|
34 | printme(map[0], map[1])
| ^^^^^^ cannot move out of here
I'm aware of the fact I could implement the Copy
trait, but I actually don't need copy of data in this case. Hence I'm looking for a cleaner solution.