From 0b55ae47c6759e3e5801e031dfa1e20b64955291 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Tue, 26 Jul 2022 23:22:39 +0800 Subject: [PATCH 1/2] Add From for EntityRef (fixes #5459) --- crates/bevy_ecs/src/world/entity_ref.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 7d1051bba1988..983cb62a60c56 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -128,6 +128,16 @@ impl<'w> EntityRef<'w> { } } +impl<'w> From> for EntityRef<'w> { + fn from(entity_mut: EntityMut<'w>) -> EntityRef<'w> { + EntityRef { + world: entity_mut.world, + entity: entity_mut.entity, + location: entity_mut.location, + } + } +} + /// A mutable reference to a particular [`Entity`] and all of its components pub struct EntityMut<'w> { world: &'w mut World, From 0163bddc967ec4020be7ae6e70316deb33d94ca0 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sat, 30 Jul 2022 23:20:44 +0800 Subject: [PATCH 2/2] Use EntityRef::new instead of struct syntax --- crates/bevy_ecs/src/world/entity_ref.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 983cb62a60c56..4c09aaae7a796 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -130,11 +130,7 @@ impl<'w> EntityRef<'w> { impl<'w> From> for EntityRef<'w> { fn from(entity_mut: EntityMut<'w>) -> EntityRef<'w> { - EntityRef { - world: entity_mut.world, - entity: entity_mut.entity, - location: entity_mut.location, - } + EntityRef::new(entity_mut.world, entity_mut.entity, entity_mut.location) } }