Skip to content

Commit

Permalink
Implement SparseSetIndex for WorldId (#7125)
Browse files Browse the repository at this point in the history
# Objective

- Fixes #7124

## Solution

- Add Hash Derive on `WorldId`
- Add `SparseSetIndex` impl
  • Loading branch information
2ne1ugly committed Jan 9, 2023
1 parent 789cb83 commit ec638ad
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/bevy_ecs/src/world/identifier.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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::*;
Expand Down

0 comments on commit ec638ad

Please sign in to comment.