From 0e9f80e00b513fd7cb17bf971a970d23f902bde4 Mon Sep 17 00:00:00 2001 From: 2ne1ugly <47616772+2ne1ugly@users.noreply.github.com> Date: Mon, 9 Jan 2023 21:43:27 +0000 Subject: [PATCH] Implement `SparseSetIndex` for `WorldId` (#7125) # Objective - Fixes #7124 ## Solution - Add Hash Derive on `WorldId` - Add `SparseSetIndex` impl --- crates/bevy_ecs/src/world/identifier.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/world/identifier.rs b/crates/bevy_ecs/src/world/identifier.rs index 6e2b8efc0f222..c65da1b81a7e1 100644 --- a/crates/bevy_ecs/src/world/identifier.rs +++ b/crates/bevy_ecs/src/world/identifier.rs @@ -1,6 +1,7 @@ +use crate::storage::SparseSetIndex; use std::sync::atomic::{AtomicUsize, Ordering}; -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] // We use usize here because that is the largest `Atomic` we want to require /// A unique identifier for a [`super::World`]. // Note that this *is* used by external crates as well as for internal safety checks @@ -26,6 +27,17 @@ impl WorldId { } } +impl SparseSetIndex for WorldId { + #[inline] + fn sparse_set_index(&self) -> usize { + self.0 + } + + fn get_sparse_set_index(value: usize) -> Self { + Self(value) + } +} + #[cfg(test)] mod tests { use super::*;