#[derive(Entity)]
{
// Attributes available to this derive:
#[dervy]
}
Expand description
Derive PartialEq, Eq, and Hash for this entity type by considering
the field annotated with #[dervy(id)]
Example:
#[derive(Clone, Debug, dervy::Entity)]
struct MyEntity {
#[dervy(id)]
my_entity_id: i32,
other_field: bool,
// ...
}
// structs are equal by value
let ent1 = MyEntity { my_entity_id: 0, other_field: false };
let mut ent2 = ent1.clone();
assert_eq!(ent1, ent2);
// structs are still equal by identity
ent2.other_field = true;
assert_eq!(ent1, ent2);
// structs are no longer equal by identity
ent2.my_entity_id += 1;
assert_ne!(ent1, ent2);
ent2.my_entity_id -= 1;
// structs are hashed by identity
let mut map = std::collections::HashMap::<MyEntity, bool>::new();
map.insert(ent1, true);
assert!(map.contains_key(&ent2));