Skip to content

impl Hash for Gd<T> per instance ID #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,16 @@ impl<T: GodotClass> Debug for Gd<T> {
}
}

impl<T: GodotClass> std::hash::Hash for Gd<T> {
/// ⚠️ Hashes this object based on its instance ID.
///
/// # Panics
/// When `self` is dead.
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.instance_id().hash(state);
}
}

// Gd unwinding across panics does not invalidate any invariants;
// its mutability is anyway present, in the Godot engine.
impl<T: GodotClass> std::panic::UnwindSafe for Gd<T> {}
Expand Down