Skip to content
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

Implement the alternate solution for GitHub issue #9321, implementing Deref and DerefMut for EntityMap #9357

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 14 additions & 0 deletions crates/bevy_ecs/src/entity/map_entities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{entity::Entity, world::World};
use bevy_utils::{Entry, HashMap};
use core::ops::{Deref, DerefMut};

/// Operation to map all contained [`Entity`] fields in a type to new values.
///
Expand Down Expand Up @@ -129,6 +130,19 @@ impl EntityMap {
}
}

impl Deref for EntityMap {
type Target = HashMap<Entity, Entity>;
fn deref(&self) -> &Self::Target {
&self.map
}
}

impl DerefMut for EntityMap {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.map
}
}

/// A wrapper for [`EntityMap`], augmenting it with the ability to allocate new [`Entity`] references in a destination
/// world. These newly allocated references are guaranteed to never point to any living entity in that world.
///
Expand Down