Skip to content

Commit ec638ad

Browse files
committed
Implement SparseSetIndex for WorldId (#7125)
# Objective - Fixes #7124 ## Solution - Add Hash Derive on `WorldId` - Add `SparseSetIndex` impl
1 parent 789cb83 commit ec638ad

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

crates/bevy_ecs/src/world/identifier.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use crate::storage::SparseSetIndex;
12
use std::sync::atomic::{AtomicUsize, Ordering};
23

3-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
4+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
45
// We use usize here because that is the largest `Atomic` we want to require
56
/// A unique identifier for a [`super::World`].
67
// Note that this *is* used by external crates as well as for internal safety checks
@@ -26,6 +27,17 @@ impl WorldId {
2627
}
2728
}
2829

30+
impl SparseSetIndex for WorldId {
31+
#[inline]
32+
fn sparse_set_index(&self) -> usize {
33+
self.0
34+
}
35+
36+
fn get_sparse_set_index(value: usize) -> Self {
37+
Self(value)
38+
}
39+
}
40+
2941
#[cfg(test)]
3042
mod tests {
3143
use super::*;

0 commit comments

Comments
 (0)