I have this code:
use std::collections::HashMap;
#[derive(Copy, Clone, PartialEq, Hash, Debug)]
struct Coord(i32, i32);
#[derive(Copy, Clone, PartialEq, Debug)]
enum State {
OFF,
ON,
MID,
}
type NewMapType = HashMap<Coord, State>;
fn do_map_operation(some_map: &NewMapType) -> i32 {
let mut answer = 0;
for (key, value) in some_map.into_iter() {
let new_point = call_another_function(&some_map);
// This is an error - the compiler complains that this `some_map`
// does not implement the Copy trait but whereas
// both the key and the value implement the Copy trait.
answer += new_point;
}
answer
}
fn main() {
let mut newMap: NewMapType = HashMap::new();
newMap.insert(Coord(0, 0), STATE::OFF);
let some_answer = do_map_operation(&newMap);
println!("{}", some_answer);
}
How should I be implementing the Copy
trait for a HashMap
so that I can safely use copies of the map across multiple functions?