Skip to content

Commit 030edbf

Browse files
Rename bevy_ecs::world::Entry to ComponentEntry (#19517)
# Objective As discussed in #19285, some of our names conflict. `Entry` in bevy_ecs is one of those overly general names. ## Solution Rename this type (and the related types) to `ComponentEntry`. --------- Co-authored-by: urben1680 <[email protected]>
1 parent 6ddd0f1 commit 030edbf

File tree

4 files changed

+69
-60
lines changed

4 files changed

+69
-60
lines changed

crates/bevy_ecs/src/world/entity_ref.rs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,14 +2607,14 @@ impl<'w> EntityWorldMut<'w> {
26072607
/// # Panics
26082608
///
26092609
/// If the entity has been despawned while this `EntityWorldMut` is still alive.
2610-
pub fn entry<'a, T: Component>(&'a mut self) -> Entry<'w, 'a, T> {
2610+
pub fn entry<'a, T: Component>(&'a mut self) -> ComponentEntry<'w, 'a, T> {
26112611
if self.contains::<T>() {
2612-
Entry::Occupied(OccupiedEntry {
2612+
ComponentEntry::Occupied(OccupiedComponentEntry {
26132613
entity_world: self,
26142614
_marker: PhantomData,
26152615
})
26162616
} else {
2617-
Entry::Vacant(VacantEntry {
2617+
ComponentEntry::Vacant(VacantComponentEntry {
26182618
entity_world: self,
26192619
_marker: PhantomData,
26202620
})
@@ -2857,14 +2857,14 @@ impl<'w> EntityWorldMut<'w> {
28572857
/// This `enum` can only be constructed from the [`entry`] method on [`EntityWorldMut`].
28582858
///
28592859
/// [`entry`]: EntityWorldMut::entry
2860-
pub enum Entry<'w, 'a, T: Component> {
2860+
pub enum ComponentEntry<'w, 'a, T: Component> {
28612861
/// An occupied entry.
2862-
Occupied(OccupiedEntry<'w, 'a, T>),
2862+
Occupied(OccupiedComponentEntry<'w, 'a, T>),
28632863
/// A vacant entry.
2864-
Vacant(VacantEntry<'w, 'a, T>),
2864+
Vacant(VacantComponentEntry<'w, 'a, T>),
28652865
}
28662866

2867-
impl<'w, 'a, T: Component<Mutability = Mutable>> Entry<'w, 'a, T> {
2867+
impl<'w, 'a, T: Component<Mutability = Mutable>> ComponentEntry<'w, 'a, T> {
28682868
/// Provides in-place mutable access to an occupied entry.
28692869
///
28702870
/// # Examples
@@ -2883,17 +2883,17 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> Entry<'w, 'a, T> {
28832883
#[inline]
28842884
pub fn and_modify<F: FnOnce(Mut<'_, T>)>(self, f: F) -> Self {
28852885
match self {
2886-
Entry::Occupied(mut entry) => {
2886+
ComponentEntry::Occupied(mut entry) => {
28872887
f(entry.get_mut());
2888-
Entry::Occupied(entry)
2888+
ComponentEntry::Occupied(entry)
28892889
}
2890-
Entry::Vacant(entry) => Entry::Vacant(entry),
2890+
ComponentEntry::Vacant(entry) => ComponentEntry::Vacant(entry),
28912891
}
28922892
}
28932893
}
28942894

2895-
impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
2896-
/// Replaces the component of the entry, and returns an [`OccupiedEntry`].
2895+
impl<'w, 'a, T: Component> ComponentEntry<'w, 'a, T> {
2896+
/// Replaces the component of the entry, and returns an [`OccupiedComponentEntry`].
28972897
///
28982898
/// # Examples
28992899
///
@@ -2912,13 +2912,13 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
29122912
/// assert_eq!(entry.get(), &Comp(2));
29132913
/// ```
29142914
#[inline]
2915-
pub fn insert_entry(self, component: T) -> OccupiedEntry<'w, 'a, T> {
2915+
pub fn insert_entry(self, component: T) -> OccupiedComponentEntry<'w, 'a, T> {
29162916
match self {
2917-
Entry::Occupied(mut entry) => {
2917+
ComponentEntry::Occupied(mut entry) => {
29182918
entry.insert(component);
29192919
entry
29202920
}
2921-
Entry::Vacant(entry) => entry.insert(component),
2921+
ComponentEntry::Vacant(entry) => entry.insert(component),
29222922
}
29232923
}
29242924

@@ -2944,10 +2944,10 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
29442944
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 8);
29452945
/// ```
29462946
#[inline]
2947-
pub fn or_insert(self, default: T) -> OccupiedEntry<'w, 'a, T> {
2947+
pub fn or_insert(self, default: T) -> OccupiedComponentEntry<'w, 'a, T> {
29482948
match self {
2949-
Entry::Occupied(entry) => entry,
2950-
Entry::Vacant(entry) => entry.insert(default),
2949+
ComponentEntry::Occupied(entry) => entry,
2950+
ComponentEntry::Vacant(entry) => entry.insert(default),
29512951
}
29522952
}
29532953

@@ -2968,15 +2968,15 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
29682968
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 4);
29692969
/// ```
29702970
#[inline]
2971-
pub fn or_insert_with<F: FnOnce() -> T>(self, default: F) -> OccupiedEntry<'w, 'a, T> {
2971+
pub fn or_insert_with<F: FnOnce() -> T>(self, default: F) -> OccupiedComponentEntry<'w, 'a, T> {
29722972
match self {
2973-
Entry::Occupied(entry) => entry,
2974-
Entry::Vacant(entry) => entry.insert(default()),
2973+
ComponentEntry::Occupied(entry) => entry,
2974+
ComponentEntry::Vacant(entry) => entry.insert(default()),
29752975
}
29762976
}
29772977
}
29782978

2979-
impl<'w, 'a, T: Component + Default> Entry<'w, 'a, T> {
2979+
impl<'w, 'a, T: Component + Default> ComponentEntry<'w, 'a, T> {
29802980
/// Ensures the entry has this component by inserting the default value if empty, and
29812981
/// returns a mutable reference to this component in the entry.
29822982
///
@@ -2994,42 +2994,42 @@ impl<'w, 'a, T: Component + Default> Entry<'w, 'a, T> {
29942994
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 0);
29952995
/// ```
29962996
#[inline]
2997-
pub fn or_default(self) -> OccupiedEntry<'w, 'a, T> {
2997+
pub fn or_default(self) -> OccupiedComponentEntry<'w, 'a, T> {
29982998
match self {
2999-
Entry::Occupied(entry) => entry,
3000-
Entry::Vacant(entry) => entry.insert(Default::default()),
2999+
ComponentEntry::Occupied(entry) => entry,
3000+
ComponentEntry::Vacant(entry) => entry.insert(Default::default()),
30013001
}
30023002
}
30033003
}
30043004

3005-
/// A view into an occupied entry in a [`EntityWorldMut`]. It is part of the [`Entry`] enum.
3005+
/// A view into an occupied entry in a [`EntityWorldMut`]. It is part of the [`OccupiedComponentEntry`] enum.
30063006
///
30073007
/// The contained entity must have the component type parameter if we have this struct.
3008-
pub struct OccupiedEntry<'w, 'a, T: Component> {
3008+
pub struct OccupiedComponentEntry<'w, 'a, T: Component> {
30093009
entity_world: &'a mut EntityWorldMut<'w>,
30103010
_marker: PhantomData<T>,
30113011
}
30123012

3013-
impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
3013+
impl<'w, 'a, T: Component> OccupiedComponentEntry<'w, 'a, T> {
30143014
/// Gets a reference to the component in the entry.
30153015
///
30163016
/// # Examples
30173017
///
30183018
/// ```
3019-
/// # use bevy_ecs::{prelude::*, world::Entry};
3019+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
30203020
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
30213021
/// struct Comp(u32);
30223022
///
30233023
/// # let mut world = World::new();
30243024
/// let mut entity = world.spawn(Comp(5));
30253025
///
3026-
/// if let Entry::Occupied(o) = entity.entry::<Comp>() {
3026+
/// if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
30273027
/// assert_eq!(o.get().0, 5);
30283028
/// }
30293029
/// ```
30303030
#[inline]
30313031
pub fn get(&self) -> &T {
3032-
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
3032+
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
30333033
self.entity_world.get::<T>().unwrap()
30343034
}
30353035

@@ -3038,14 +3038,14 @@ impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
30383038
/// # Examples
30393039
///
30403040
/// ```
3041-
/// # use bevy_ecs::{prelude::*, world::Entry};
3041+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
30423042
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
30433043
/// struct Comp(u32);
30443044
///
30453045
/// # let mut world = World::new();
30463046
/// let mut entity = world.spawn(Comp(5));
30473047
///
3048-
/// if let Entry::Occupied(mut o) = entity.entry::<Comp>() {
3048+
/// if let ComponentEntry::Occupied(mut o) = entity.entry::<Comp>() {
30493049
/// o.insert(Comp(10));
30503050
/// }
30513051
///
@@ -3061,45 +3061,45 @@ impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
30613061
/// # Examples
30623062
///
30633063
/// ```
3064-
/// # use bevy_ecs::{prelude::*, world::Entry};
3064+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
30653065
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
30663066
/// struct Comp(u32);
30673067
///
30683068
/// # let mut world = World::new();
30693069
/// let mut entity = world.spawn(Comp(5));
30703070
///
3071-
/// if let Entry::Occupied(o) = entity.entry::<Comp>() {
3071+
/// if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
30723072
/// assert_eq!(o.take(), Comp(5));
30733073
/// }
30743074
///
30753075
/// assert_eq!(world.query::<&Comp>().iter(&world).len(), 0);
30763076
/// ```
30773077
#[inline]
30783078
pub fn take(self) -> T {
3079-
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
3079+
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
30803080
self.entity_world.take().unwrap()
30813081
}
30823082
}
30833083

3084-
impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
3084+
impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedComponentEntry<'w, 'a, T> {
30853085
/// Gets a mutable reference to the component in the entry.
30863086
///
3087-
/// If you need a reference to the `OccupiedEntry` which may outlive the destruction of
3088-
/// the `Entry` value, see [`into_mut`].
3087+
/// If you need a reference to the [`OccupiedComponentEntry`] which may outlive the destruction of
3088+
/// the [`OccupiedComponentEntry`] value, see [`into_mut`].
30893089
///
30903090
/// [`into_mut`]: Self::into_mut
30913091
///
30923092
/// # Examples
30933093
///
30943094
/// ```
3095-
/// # use bevy_ecs::{prelude::*, world::Entry};
3095+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
30963096
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
30973097
/// struct Comp(u32);
30983098
///
30993099
/// # let mut world = World::new();
31003100
/// let mut entity = world.spawn(Comp(5));
31013101
///
3102-
/// if let Entry::Occupied(mut o) = entity.entry::<Comp>() {
3102+
/// if let ComponentEntry::Occupied(mut o) = entity.entry::<Comp>() {
31033103
/// o.get_mut().0 += 10;
31043104
/// assert_eq!(o.get().0, 15);
31053105
///
@@ -3111,69 +3111,69 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
31113111
/// ```
31123112
#[inline]
31133113
pub fn get_mut(&mut self) -> Mut<'_, T> {
3114-
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
3114+
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
31153115
self.entity_world.get_mut::<T>().unwrap()
31163116
}
31173117

3118-
/// Converts the `OccupiedEntry` into a mutable reference to the value in the entry with
3118+
/// Converts the [`OccupiedComponentEntry`] into a mutable reference to the value in the entry with
31193119
/// a lifetime bound to the `EntityWorldMut`.
31203120
///
3121-
/// If you need multiple references to the `OccupiedEntry`, see [`get_mut`].
3121+
/// If you need multiple references to the [`OccupiedComponentEntry`], see [`get_mut`].
31223122
///
31233123
/// [`get_mut`]: Self::get_mut
31243124
///
31253125
/// # Examples
31263126
///
31273127
/// ```
3128-
/// # use bevy_ecs::{prelude::*, world::Entry};
3128+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
31293129
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
31303130
/// struct Comp(u32);
31313131
///
31323132
/// # let mut world = World::new();
31333133
/// let mut entity = world.spawn(Comp(5));
31343134
///
3135-
/// if let Entry::Occupied(o) = entity.entry::<Comp>() {
3135+
/// if let ComponentEntry::Occupied(o) = entity.entry::<Comp>() {
31363136
/// o.into_mut().0 += 10;
31373137
/// }
31383138
///
31393139
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 15);
31403140
/// ```
31413141
#[inline]
31423142
pub fn into_mut(self) -> Mut<'a, T> {
3143-
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
3143+
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
31443144
self.entity_world.get_mut().unwrap()
31453145
}
31463146
}
31473147

3148-
/// A view into a vacant entry in a [`EntityWorldMut`]. It is part of the [`Entry`] enum.
3149-
pub struct VacantEntry<'w, 'a, T: Component> {
3148+
/// A view into a vacant entry in a [`EntityWorldMut`]. It is part of the [`ComponentEntry`] enum.
3149+
pub struct VacantComponentEntry<'w, 'a, T: Component> {
31503150
entity_world: &'a mut EntityWorldMut<'w>,
31513151
_marker: PhantomData<T>,
31523152
}
31533153

3154-
impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> {
3155-
/// Inserts the component into the `VacantEntry` and returns an `OccupiedEntry`.
3154+
impl<'w, 'a, T: Component> VacantComponentEntry<'w, 'a, T> {
3155+
/// Inserts the component into the [`VacantComponentEntry`] and returns an [`OccupiedComponentEntry`].
31563156
///
31573157
/// # Examples
31583158
///
31593159
/// ```
3160-
/// # use bevy_ecs::{prelude::*, world::Entry};
3160+
/// # use bevy_ecs::{prelude::*, world::ComponentEntry};
31613161
/// #[derive(Component, Default, Clone, Copy, Debug, PartialEq)]
31623162
/// struct Comp(u32);
31633163
///
31643164
/// # let mut world = World::new();
31653165
/// let mut entity = world.spawn_empty();
31663166
///
3167-
/// if let Entry::Vacant(v) = entity.entry::<Comp>() {
3167+
/// if let ComponentEntry::Vacant(v) = entity.entry::<Comp>() {
31683168
/// v.insert(Comp(10));
31693169
/// }
31703170
///
31713171
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 10);
31723172
/// ```
31733173
#[inline]
3174-
pub fn insert(self, component: T) -> OccupiedEntry<'w, 'a, T> {
3174+
pub fn insert(self, component: T) -> OccupiedComponentEntry<'w, 'a, T> {
31753175
self.entity_world.insert(component);
3176-
OccupiedEntry {
3176+
OccupiedComponentEntry {
31773177
entity_world: self.entity_world,
31783178
_marker: PhantomData,
31793179
}
@@ -3184,7 +3184,7 @@ impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> {
31843184
///
31853185
/// To define the access when used as a [`QueryData`](crate::query::QueryData),
31863186
/// use a [`QueryBuilder`](crate::query::QueryBuilder) or [`QueryParamBuilder`](crate::system::QueryParamBuilder).
3187-
/// The `FilteredEntityRef` must be the entire `QueryData`, and not nested inside a tuple with other data.
3187+
/// The [`FilteredEntityRef`] must be the entire [`QueryData`](crate::query::QueryData), and not nested inside a tuple with other data.
31883188
///
31893189
/// ```
31903190
/// # use bevy_ecs::{prelude::*, world::FilteredEntityRef};

crates/bevy_ecs/src/world/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ pub use bevy_ecs_macros::FromWorld;
2626
pub use deferred_world::DeferredWorld;
2727
pub use entity_fetch::{EntityFetcher, WorldEntityFetch};
2828
pub use entity_ref::{
29-
DynamicComponentFetch, EntityMut, EntityMutExcept, EntityRef, EntityRefExcept, EntityWorldMut,
30-
Entry, FilteredEntityMut, FilteredEntityRef, OccupiedEntry, TryFromFilteredError, VacantEntry,
29+
ComponentEntry, DynamicComponentFetch, EntityMut, EntityMutExcept, EntityRef, EntityRefExcept,
30+
EntityWorldMut, FilteredEntityMut, FilteredEntityRef, OccupiedComponentEntry,
31+
TryFromFilteredError, VacantComponentEntry,
3132
};
3233
pub use filtered_resource::*;
3334
pub use identifier::WorldId;

crates/bevy_render/src/sync_world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl
220220
EntityRecord::Added(e) => {
221221
if let Ok(mut main_entity) = world.get_entity_mut(e) {
222222
match main_entity.entry::<RenderEntity>() {
223-
bevy_ecs::world::Entry::Occupied(_) => {
223+
bevy_ecs::world::ComponentEntry::Occupied(_) => {
224224
panic!("Attempting to synchronize an entity that has already been synchronized!");
225225
}
226-
bevy_ecs::world::Entry::Vacant(entry) => {
226+
bevy_ecs::world::ComponentEntry::Vacant(entry) => {
227227
let id = render_world.spawn(MainEntity(e)).id();
228228

229229
entry.insert(RenderEntity(id));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: `Entry` enum is now `ComponentEntry`
3+
pull_requests: [TODO]
4+
---
5+
6+
The `Entry` enum in `bevy::ecs::world` has been renamed to `ComponentEntry`, to avoid name clashes with `hash_map`, `hash_table` and `hash_set` `Entry` types.
7+
8+
Correspondingly, the nested `OccupiedEntry` and `VacantEntry` enums have been renamed to `OccupiedComponentEntry` and `VacantComponentEntry`.

0 commit comments

Comments
 (0)