Skip to content

Rename bevy_ecs::world::Entry to ComponentEntry #19517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2600,14 +2600,14 @@ impl<'w> EntityWorldMut<'w> {
/// # Panics
///
/// If the entity has been despawned while this `EntityWorldMut` is still alive.
pub fn entry<'a, T: Component>(&'a mut self) -> Entry<'w, 'a, T> {
pub fn entry<'a, T: Component>(&'a mut self) -> ComponentEntry<'w, 'a, T> {
if self.contains::<T>() {
Entry::Occupied(OccupiedEntry {
ComponentEntry::Occupied(OccupiedComponentEntry {
entity_world: self,
_marker: PhantomData,
})
} else {
Entry::Vacant(VacantEntry {
ComponentEntry::Vacant(VacantComponentEntry {
entity_world: self,
_marker: PhantomData,
})
Expand Down Expand Up @@ -2850,14 +2850,14 @@ impl<'w> EntityWorldMut<'w> {
/// This `enum` can only be constructed from the [`entry`] method on [`EntityWorldMut`].
///
/// [`entry`]: EntityWorldMut::entry
pub enum Entry<'w, 'a, T: Component> {
pub enum ComponentEntry<'w, 'a, T: Component> {
/// An occupied entry.
Occupied(OccupiedEntry<'w, 'a, T>),
Occupied(OccupiedComponentEntry<'w, 'a, T>),
/// A vacant entry.
Vacant(VacantEntry<'w, 'a, T>),
Vacant(VacantComponentEntry<'w, 'a, T>),
}

impl<'w, 'a, T: Component<Mutability = Mutable>> Entry<'w, 'a, T> {
impl<'w, 'a, T: Component<Mutability = Mutable>> ComponentEntry<'w, 'a, T> {
/// Provides in-place mutable access to an occupied entry.
///
/// # Examples
Expand All @@ -2876,17 +2876,17 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> Entry<'w, 'a, T> {
#[inline]
pub fn and_modify<F: FnOnce(Mut<'_, T>)>(self, f: F) -> Self {
match self {
Entry::Occupied(mut entry) => {
ComponentEntry::Occupied(mut entry) => {
f(entry.get_mut());
Entry::Occupied(entry)
ComponentEntry::Occupied(entry)
}
Entry::Vacant(entry) => Entry::Vacant(entry),
ComponentEntry::Vacant(entry) => ComponentEntry::Vacant(entry),
}
}
}

impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
/// Replaces the component of the entry, and returns an [`OccupiedEntry`].
impl<'w, 'a, T: Component> ComponentEntry<'w, 'a, T> {
/// Replaces the component of the entry, and returns an [`OccupiedComponentEntry`].
///
/// # Examples
///
Expand All @@ -2905,13 +2905,13 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
/// assert_eq!(entry.get(), &Comp(2));
/// ```
#[inline]
pub fn insert_entry(self, component: T) -> OccupiedEntry<'w, 'a, T> {
pub fn insert_entry(self, component: T) -> OccupiedComponentEntry<'w, 'a, T> {
match self {
Entry::Occupied(mut entry) => {
ComponentEntry::Occupied(mut entry) => {
entry.insert(component);
entry
}
Entry::Vacant(entry) => entry.insert(component),
ComponentEntry::Vacant(entry) => entry.insert(component),
}
}

Expand All @@ -2937,10 +2937,10 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 8);
/// ```
#[inline]
pub fn or_insert(self, default: T) -> OccupiedEntry<'w, 'a, T> {
pub fn or_insert(self, default: T) -> OccupiedComponentEntry<'w, 'a, T> {
match self {
Entry::Occupied(entry) => entry,
Entry::Vacant(entry) => entry.insert(default),
ComponentEntry::Occupied(entry) => entry,
ComponentEntry::Vacant(entry) => entry.insert(default),
}
}

Expand All @@ -2961,15 +2961,15 @@ impl<'w, 'a, T: Component> Entry<'w, 'a, T> {
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 4);
/// ```
#[inline]
pub fn or_insert_with<F: FnOnce() -> T>(self, default: F) -> OccupiedEntry<'w, 'a, T> {
pub fn or_insert_with<F: FnOnce() -> T>(self, default: F) -> OccupiedComponentEntry<'w, 'a, T> {
match self {
Entry::Occupied(entry) => entry,
Entry::Vacant(entry) => entry.insert(default()),
ComponentEntry::Occupied(entry) => entry,
ComponentEntry::Vacant(entry) => entry.insert(default()),
}
}
}

impl<'w, 'a, T: Component + Default> Entry<'w, 'a, T> {
impl<'w, 'a, T: Component + Default> ComponentEntry<'w, 'a, T> {
/// Ensures the entry has this component by inserting the default value if empty, and
/// returns a mutable reference to this component in the entry.
///
Expand All @@ -2987,23 +2987,23 @@ impl<'w, 'a, T: Component + Default> Entry<'w, 'a, T> {
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 0);
/// ```
#[inline]
pub fn or_default(self) -> OccupiedEntry<'w, 'a, T> {
pub fn or_default(self) -> OccupiedComponentEntry<'w, 'a, T> {
match self {
Entry::Occupied(entry) => entry,
Entry::Vacant(entry) => entry.insert(Default::default()),
ComponentEntry::Occupied(entry) => entry,
ComponentEntry::Vacant(entry) => entry.insert(Default::default()),
}
}
}

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

impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
impl<'w, 'a, T: Component> OccupiedComponentEntry<'w, 'a, T> {
/// Gets a reference to the component in the entry.
///
/// # Examples
Expand All @@ -3022,7 +3022,7 @@ impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
/// ```
#[inline]
pub fn get(&self) -> &T {
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
self.entity_world.get::<T>().unwrap()
}

Expand Down Expand Up @@ -3069,16 +3069,16 @@ impl<'w, 'a, T: Component> OccupiedEntry<'w, 'a, T> {
/// ```
#[inline]
pub fn take(self) -> T {
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
self.entity_world.take().unwrap()
}
}

impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedComponentEntry<'w, 'a, T> {
/// Gets a mutable reference to the component in the entry.
///
/// If you need a reference to the `OccupiedEntry` which may outlive the destruction of
/// the `Entry` value, see [`into_mut`].
/// If you need a reference to the [`OccupiedComponentEntry`] which may outlive the destruction of
/// the [`OccupiedComponentEntry`] value, see [`into_mut`].
///
/// [`into_mut`]: Self::into_mut
///
Expand All @@ -3092,7 +3092,7 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
/// # let mut world = World::new();
/// let mut entity = world.spawn(Comp(5));
///
/// if let Entry::Occupied(mut o) = entity.entry::<Comp>() {
/// if let ComponentEntry::Occupied(mut o) = entity.entry::<Comp>() {
/// o.get_mut().0 += 10;
/// assert_eq!(o.get().0, 15);
///
Expand All @@ -3104,14 +3104,14 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
/// ```
#[inline]
pub fn get_mut(&mut self) -> Mut<'_, T> {
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
self.entity_world.get_mut::<T>().unwrap()
}

/// Converts the `OccupiedEntry` into a mutable reference to the value in the entry with
/// Converts the [`OccupiedComponentEntry`] into a mutable reference to the value in the entry with
/// a lifetime bound to the `EntityWorldMut`.
///
/// If you need multiple references to the `OccupiedEntry`, see [`get_mut`].
/// If you need multiple references to the [`OccupiedComponentEntry`], see [`get_mut`].
///
/// [`get_mut`]: Self::get_mut
///
Expand All @@ -3133,19 +3133,19 @@ impl<'w, 'a, T: Component<Mutability = Mutable>> OccupiedEntry<'w, 'a, T> {
/// ```
#[inline]
pub fn into_mut(self) -> Mut<'a, T> {
// This shouldn't panic because if we have an OccupiedEntry the component must exist.
// This shouldn't panic because if we have an OccupiedComponentEntry the component must exist.
self.entity_world.get_mut().unwrap()
}
}

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

impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> {
/// Inserts the component into the `VacantEntry` and returns an `OccupiedEntry`.
impl<'w, 'a, T: Component> VacantComponentEntry<'w, 'a, T> {
/// Inserts the component into the [`VacantComponentEntry`] and returns an [`OccupiedComponentEntry`].
///
/// # Examples
///
Expand All @@ -3164,9 +3164,9 @@ impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> {
/// assert_eq!(world.query::<&Comp>().single(&world).unwrap().0, 10);
/// ```
#[inline]
pub fn insert(self, component: T) -> OccupiedEntry<'w, 'a, T> {
pub fn insert(self, component: T) -> OccupiedComponentEntry<'w, 'a, T> {
self.entity_world.insert(component);
OccupiedEntry {
OccupiedComponentEntry {
entity_world: self.entity_world,
_marker: PhantomData,
}
Expand All @@ -3177,7 +3177,7 @@ impl<'w, 'a, T: Component> VacantEntry<'w, 'a, T> {
///
/// To define the access when used as a [`QueryData`](crate::query::QueryData),
/// use a [`QueryBuilder`](crate::query::QueryBuilder) or [`QueryParamBuilder`](crate::system::QueryParamBuilder).
/// The `FilteredEntityRef` must be the entire `QueryData`, and not nested inside a tuple with other data.
/// The [`FilteredEntityRef`] must be the entire [`QueryData`](crate::query::QueryData), and not nested inside a tuple with other data.
///
/// ```
/// # use bevy_ecs::{prelude::*, world::FilteredEntityRef};
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ pub use component_constants::*;
pub use deferred_world::DeferredWorld;
pub use entity_fetch::{EntityFetcher, WorldEntityFetch};
pub use entity_ref::{
DynamicComponentFetch, EntityMut, EntityMutExcept, EntityRef, EntityRefExcept, EntityWorldMut,
Entry, FilteredEntityMut, FilteredEntityRef, OccupiedEntry, TryFromFilteredError, VacantEntry,
ComponentEntry, DynamicComponentFetch, EntityMut, EntityMutExcept, EntityRef, EntityRefExcept,
EntityWorldMut, FilteredEntityMut, FilteredEntityRef, OccupiedComponentEntry,
TryFromFilteredError, VacantComponentEntry,
};
pub use filtered_resource::*;
pub use identifier::WorldId;
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/sync_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ pub(crate) fn entity_sync_system(main_world: &mut World, render_world: &mut Worl
EntityRecord::Added(e) => {
if let Ok(mut main_entity) = world.get_entity_mut(e) {
match main_entity.entry::<RenderEntity>() {
bevy_ecs::world::Entry::Occupied(_) => {
bevy_ecs::world::ComponentEntry::Occupied(_) => {
panic!("Attempting to synchronize an entity that has already been synchronized!");
}
bevy_ecs::world::Entry::Vacant(entry) => {
bevy_ecs::world::ComponentEntry::Vacant(entry) => {
let id = render_world.spawn(MainEntity(e)).id();

entry.insert(RenderEntity(id));
Expand Down
8 changes: 8 additions & 0 deletions release-content/migration-guides/component_entry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: `Entry` enum is now `ComponentEntry`
pull_requests: [TODO]
---

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.

Correspondingly, the nested `OccupiedEntry` and `VacantEntry` enums have been renamed to `OccupiedComponentEntry` and `VacantComponentEntry`.
Loading