Skip to content

Commit e2805be

Browse files
committed
impl Hash for Gd<T> per instance ID
1 parent 6b99bc9 commit e2805be

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

godot-core/src/obj/gd.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ impl<T: GodotClass> Debug for Gd<T> {
654654
}
655655
}
656656

657+
impl<T: GodotClass> std::hash::Hash for Gd<T> {
658+
/// ⚠️ Hashes this object based on it's instance ID.
659+
///
660+
/// # Panics
661+
/// When `self` is dead.
662+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
663+
self.instance_id().hash(state);
664+
}
665+
}
666+
657667
// Gd unwinding across panics does not invalidate any invariants;
658668
// its mutability is anyway present, in the Godot engine.
659669
impl<T: GodotClass> std::panic::UnwindSafe for Gd<T> {}

0 commit comments

Comments
 (0)