Skip to content

Commit 404b4fc

Browse files
committed
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
1 parent 05afbc6 commit 404b4fc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

crates/bevy_ecs/src/world/entity_ref.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bevy_ptr::{OwningPtr, Ptr, UnsafeCellDeref};
1111
use std::{any::TypeId, cell::UnsafeCell};
1212

1313
/// A read-only reference to a particular [`Entity`] and all of its components
14+
#[derive(Copy, Clone)]
1415
pub struct EntityRef<'w> {
1516
world: &'w World,
1617
entity: Entity,
@@ -44,7 +45,7 @@ impl<'w> EntityRef<'w> {
4445
}
4546

4647
#[inline]
47-
pub fn world(&mut self) -> &World {
48+
pub fn world(&self) -> &'w World {
4849
self.world
4950
}
5051

@@ -497,7 +498,7 @@ impl<'w> EntityMut<'w> {
497498
}
498499

499500
#[inline]
500-
pub fn world(&mut self) -> &World {
501+
pub fn world(&self) -> &World {
501502
self.world
502503
}
503504

0 commit comments

Comments
 (0)