Skip to content

Commit

Permalink
lifetime related cleanup in entity_ref.rs (#5611)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
BoxyUwU committed Sep 12, 2022
1 parent 05afbc6 commit 404b4fc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,7 +45,7 @@ impl<'w> EntityRef<'w> {
}

#[inline]
pub fn world(&mut self) -> &World {
pub fn world(&self) -> &'w World {
self.world
}

Expand Down Expand Up @@ -497,7 +498,7 @@ impl<'w> EntityMut<'w> {
}

#[inline]
pub fn world(&mut self) -> &World {
pub fn world(&self) -> &World {
self.world
}

Expand Down

0 comments on commit 404b4fc

Please sign in to comment.