Closed
Description
struct Item { value: i32, id: &'static str }
impl PartialEq for Item {
fn eq(&self, other: &Item) -> bool { self.value == other.value }
}
impl Eq for Item {}
impl std::hash::Hash for Item {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.value.hash(state);
}
}
fn main() {
use indexmap::map::{IndexMap as Map, Entry};
let mut map = Map::new();
map.insert(Item { value: 3, id: "old" }, 200);
match map.entry(Item { value: 3, id: "new" }) {
Entry::Vacant(e) => panic!(),
Entry::Occupied(e) => println!("{}", e.key().id),
}
}
output:
new
Whereas if you instead use std::collections::hash_map::{HashMap as Map, Entry};
then it prints old
. This difference in behavior seems surprising.
Metadata
Metadata
Assignees
Labels
No labels