Skip to content

Commit a1e4114

Browse files
committed
Rename UnsafeWorldCellEntityRef to UnsafeEntityCell (#7568)
# Objective Make the name less verbose without sacrificing clarity. --- ## Migration Guide *Note for maintainers:* This PR has no breaking changes relative to bevy 0.9. Instead of this PR having its own migration guide, we should just edit the changelog for #6404. The type `UnsafeWorldCellEntityRef` has been renamed to `UnsafeEntityCell`.
1 parent 7eb7896 commit a1e4114

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

crates/bevy_ecs/src/reflect.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
entity::{Entity, EntityMap, MapEntities, MapEntitiesError},
77
system::Resource,
88
world::{
9-
unsafe_world_cell::{UnsafeWorldCell, UnsafeWorldCellEntityRef},
9+
unsafe_world_cell::{UnsafeEntityCell, UnsafeWorldCell},
1010
EntityMut, EntityRef, FromWorld, World,
1111
},
1212
};
@@ -61,9 +61,8 @@ pub struct ReflectComponentFns {
6161
/// Function pointer implementing [`ReflectComponent::reflect_unchecked_mut()`].
6262
///
6363
/// # Safety
64-
/// The function may only be called with an [`UnsafeWorldCellEntityRef`] that can be used to mutably access the relevant component on the given entity.
65-
pub reflect_unchecked_mut:
66-
unsafe fn(UnsafeWorldCellEntityRef<'_>) -> Option<Mut<'_, dyn Reflect>>,
64+
/// The function may only be called with an [`UnsafeEntityCell`] that can be used to mutably access the relevant component on the given entity.
65+
pub reflect_unchecked_mut: unsafe fn(UnsafeEntityCell<'_>) -> Option<Mut<'_, dyn Reflect>>,
6766
/// Function pointer implementing [`ReflectComponent::copy()`].
6867
pub copy: fn(&World, &mut World, Entity, Entity),
6968
}
@@ -126,11 +125,11 @@ impl ReflectComponent {
126125
/// # Safety
127126
/// This method does not prevent you from having two mutable pointers to the same data,
128127
/// violating Rust's aliasing rules. To avoid this:
129-
/// * Only call this method with a [`UnsafeWorldCellEntityRef`] that may be used to mutably access the component on the entity `entity`
128+
/// * Only call this method with a [`UnsafeEntityCell`] that may be used to mutably access the component on the entity `entity`
130129
/// * Don't call this method more than once in the same scope for a given [`Component`].
131130
pub unsafe fn reflect_unchecked_mut<'a>(
132131
&self,
133-
entity: UnsafeWorldCellEntityRef<'a>,
132+
entity: UnsafeEntityCell<'a>,
134133
) -> Option<Mut<'a, dyn Reflect>> {
135134
// SAFETY: safety requirements deferred to caller
136135
(self.0.reflect_unchecked_mut)(entity)
@@ -214,7 +213,7 @@ impl<C: Component + Reflect + FromWorld> FromType<C> for ReflectComponent {
214213
},
215214
reflect_unchecked_mut: |entity| {
216215
// SAFETY: reflect_unchecked_mut is an unsafe function pointer used by
217-
// `reflect_unchecked_mut` which must be called with an UnsafeWorldCellEntityRef with access to the the component `C` on the `entity`
216+
// `reflect_unchecked_mut` which must be called with an UnsafeEntityCell with access to the the component `C` on the `entity`
218217
unsafe {
219218
entity.get_mut::<C>().map(|c| Mut {
220219
value: c.value as &mut dyn Reflect,

crates/bevy_ecs/src/world/entity_ref.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use bevy_ptr::{OwningPtr, Ptr};
1212
use bevy_utils::tracing::debug;
1313
use std::any::TypeId;
1414

15-
use super::unsafe_world_cell::UnsafeWorldCellEntityRef;
15+
use super::unsafe_world_cell::UnsafeEntityCell;
1616

1717
/// A read-only reference to a particular [`Entity`] and all of its components
1818
#[derive(Copy, Clone)]
@@ -41,8 +41,8 @@ impl<'w> EntityRef<'w> {
4141
}
4242
}
4343

44-
fn as_unsafe_world_cell_readonly(&self) -> UnsafeWorldCellEntityRef<'w> {
45-
UnsafeWorldCellEntityRef::new(
44+
fn as_unsafe_world_cell_readonly(&self) -> UnsafeEntityCell<'w> {
45+
UnsafeEntityCell::new(
4646
self.world.as_unsafe_world_cell_readonly(),
4747
self.entity,
4848
self.location,
@@ -149,15 +149,15 @@ pub struct EntityMut<'w> {
149149
}
150150

151151
impl<'w> EntityMut<'w> {
152-
fn as_unsafe_world_cell_readonly(&self) -> UnsafeWorldCellEntityRef<'_> {
153-
UnsafeWorldCellEntityRef::new(
152+
fn as_unsafe_world_cell_readonly(&self) -> UnsafeEntityCell<'_> {
153+
UnsafeEntityCell::new(
154154
self.world.as_unsafe_world_cell_readonly(),
155155
self.entity,
156156
self.location,
157157
)
158158
}
159-
fn as_unsafe_world_cell(&mut self) -> UnsafeWorldCellEntityRef<'_> {
160-
UnsafeWorldCellEntityRef::new(
159+
fn as_unsafe_world_cell(&mut self) -> UnsafeEntityCell<'_> {
160+
UnsafeEntityCell::new(
161161
self.world.as_unsafe_world_cell(),
162162
self.entity,
163163
self.location,

crates/bevy_ecs/src/world/unsafe_world_cell.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ impl<'w> UnsafeWorldCell<'w> {
239239
Some(resource.id())
240240
}
241241

242-
/// Retrieves an [`UnsafeWorldCellEntityRef`] that exposes read and write operations for the given `entity`.
242+
/// Retrieves an [`UnsafeEntityCell`] that exposes read and write operations for the given `entity`.
243243
/// Similar to the [`UnsafeWorldCell`], you are in charge of making sure that no aliasing rules are violated.
244-
pub fn get_entity(self, entity: Entity) -> Option<UnsafeWorldCellEntityRef<'w>> {
244+
pub fn get_entity(self, entity: Entity) -> Option<UnsafeEntityCell<'w>> {
245245
let location = self.entities().get(entity)?;
246-
Some(UnsafeWorldCellEntityRef::new(self, entity, location))
246+
Some(UnsafeEntityCell::new(self, entity, location))
247247
}
248248

249249
/// Gets a reference to the resource of the given type if it exists
@@ -496,19 +496,19 @@ impl<'w> UnsafeWorldCell<'w> {
496496

497497
/// A interior-mutable reference to a particular [`Entity`] and all of its components
498498
#[derive(Copy, Clone)]
499-
pub struct UnsafeWorldCellEntityRef<'w> {
499+
pub struct UnsafeEntityCell<'w> {
500500
world: UnsafeWorldCell<'w>,
501501
entity: Entity,
502502
location: EntityLocation,
503503
}
504504

505-
impl<'w> UnsafeWorldCellEntityRef<'w> {
505+
impl<'w> UnsafeEntityCell<'w> {
506506
pub(crate) fn new(
507507
world: UnsafeWorldCell<'w>,
508508
entity: Entity,
509509
location: EntityLocation,
510510
) -> Self {
511-
UnsafeWorldCellEntityRef {
511+
UnsafeEntityCell {
512512
world,
513513
entity,
514514
location,
@@ -557,7 +557,7 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
557557

558558
/// # Safety
559559
/// It is the callers responsibility to ensure that
560-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component
560+
/// - the [`UnsafeEntityCell`] has permission to access the component
561561
/// - no other mutable references to the component exist at the same time
562562
#[inline]
563563
pub unsafe fn get<T: Component>(self) -> Option<&'w T> {
@@ -584,7 +584,7 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
584584
///
585585
/// # Safety
586586
/// It is the callers responsibility to ensure that
587-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component
587+
/// - the [`UnsafeEntityCell`] has permission to access the component
588588
/// - no other mutable references to the component exist at the same time
589589
#[inline]
590590
pub unsafe fn get_change_ticks<T: Component>(self) -> Option<ComponentTicks> {
@@ -607,13 +607,13 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
607607
/// Retrieves the change ticks for the given [`ComponentId`]. This can be useful for implementing change
608608
/// detection in custom runtimes.
609609
///
610-
/// **You should prefer to use the typed API [`UnsafeWorldCellEntityRef::get_change_ticks`] where possible and only
610+
/// **You should prefer to use the typed API [`UnsafeEntityCell::get_change_ticks`] where possible and only
611611
/// use this in cases where the actual component types are not known at
612612
/// compile time.**
613613
///
614614
/// # Safety
615615
/// It is the callers responsibility to ensure that
616-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component
616+
/// - the [`UnsafeEntityCell`] has permission to access the component
617617
/// - no other mutable references to the component exist at the same time
618618
#[inline]
619619
pub unsafe fn get_change_ticks_by_id(
@@ -638,7 +638,7 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
638638

639639
/// # Safety
640640
/// It is the callers responsibility to ensure that
641-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component mutably
641+
/// - the [`UnsafeEntityCell`] has permission to access the component mutably
642642
/// - no other references to the component exist at the same time
643643
#[inline]
644644
pub unsafe fn get_mut<T: Component>(self) -> Option<Mut<'w, T>> {
@@ -650,7 +650,7 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
650650

651651
/// # Safety
652652
/// It is the callers responsibility to ensure that
653-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component mutably
653+
/// - the [`UnsafeEntityCell`] has permission to access the component mutably
654654
/// - no other references to the component exist at the same time
655655
#[inline]
656656
pub(crate) unsafe fn get_mut_using_ticks<T: Component>(
@@ -680,19 +680,19 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
680680
}
681681
}
682682

683-
impl<'w> UnsafeWorldCellEntityRef<'w> {
683+
impl<'w> UnsafeEntityCell<'w> {
684684
/// Gets the component of the given [`ComponentId`] from the entity.
685685
///
686686
/// **You should prefer to use the typed API where possible and only
687687
/// use this in cases where the actual component types are not known at
688688
/// compile time.**
689689
///
690-
/// Unlike [`UnsafeWorldCellEntityRef::get`], this returns a raw pointer to the component,
690+
/// Unlike [`UnsafeEntityCell::get`], this returns a raw pointer to the component,
691691
/// which is only valid while the `'w` borrow of the lifetime is active.
692692
///
693693
/// # Safety
694694
/// It is the callers responsibility to ensure that
695-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component
695+
/// - the [`UnsafeEntityCell`] has permission to access the component
696696
/// - no other mutable references to the component exist at the same time
697697
#[inline]
698698
pub unsafe fn get_by_id(self, component_id: ComponentId) -> Option<Ptr<'w>> {
@@ -712,12 +712,12 @@ impl<'w> UnsafeWorldCellEntityRef<'w> {
712712
/// Retrieves a mutable untyped reference to the given `entity`'s [Component] of the given [`ComponentId`].
713713
/// Returns [None] if the `entity` does not have a [Component] of the given type.
714714
///
715-
/// **You should prefer to use the typed API [`UnsafeWorldCellEntityRef::get_mut`] where possible and only
715+
/// **You should prefer to use the typed API [`UnsafeEntityCell::get_mut`] where possible and only
716716
/// use this in cases where the actual types are not known at compile time.**
717717
///
718718
/// # Safety
719719
/// It is the callers responsibility to ensure that
720-
/// - the [`UnsafeWorldCellEntityRef`] has permission to access the component mutably
720+
/// - the [`UnsafeEntityCell`] has permission to access the component mutably
721721
/// - no other references to the component exist at the same time
722722
#[inline]
723723
pub unsafe fn get_mut_by_id(self, component_id: ComponentId) -> Option<MutUntyped<'w>> {

0 commit comments

Comments
 (0)