How to implement Eq and Hash for my own structs to use them as a HashMap key?
问题 I have two structs, A and B , and I want to use a HashMap<A, B> . I have a piece of code like this: use std::collections::HashMap; pub struct A { x: i32, y: i32, title: String, } pub struct B { a: u32, b: u32, } fn main() { let map = HashMap::new(); map.insert( A { x: 10, y: 20, title: "test".to_string(), }, B { a: 1, b: 2 }, ); } But the compiler gives me these errors: error[E0277]: the trait bound `A: std::cmp::Eq` is not satisfied --> src/main.rs:16:9 | 16 | map.insert( | ^^^^^^ the trait