From 404b4fc0eb96a91dcee6bc0b9e74ac00c84f14fc Mon Sep 17 00:00:00 2001 From: Boxy Date: Mon, 12 Sep 2022 04:34:52 +0000 Subject: [PATCH] lifetime related cleanup in `entity_ref.rs` (#5611) # Objective EntityMut::world takes &mut self instead of &self I don't see any reason for this. EntityRef is overly restrictive with fn world and could return &'w World --- ## Changelog - EntityRef now implements Copy and Clone - EntityRef::world is now fn(&self) -> &'w World instead of fn(&mut self) -> &World - EntityMut::world is now fn(&self) -> &World instead of fn(&mut self) -> &World --- crates/bevy_ecs/src/world/entity_ref.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index e4b7e072d4..02d5372ed9 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -11,6 +11,7 @@ use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref}; use std::{any::TypeId, cell::UnsafeCell}; /// A read-only reference to a particular [`Entity`] and all of its components +#[derive(Copy, Clone)] pub struct EntityRef<'w> { world: &'w World, entity: Entity, @@ -44,7 +45,7 @@ impl<'w> EntityRef<'w> { } #[inline] - pub fn world(&mut self) -> &World { + pub fn world(&self) -> &'w World { self.world } @@ -497,7 +498,7 @@ impl<'w> EntityMut<'w> { } #[inline] - pub fn world(&mut self) -> &World { + pub fn world(&self) -> &World { self.world }