Skip to content

Commit c9fb956

Browse files
Victoronzmockersf
authored andcommitted
use entity set collections type aliases instead of defaults (#18695)
# Objective Newest installment of the #16547 series. In #18319 we introduced `Entity` defaults to accomodate the most common use case for these types, however that resulted in the switch of the `T` and `N` generics of `UniqueEntityArray`. Swapping generics might be somewhat acceptable for `UniqueEntityArray`, it is not at all acceptable for map and set types, which we would make generic over `T: EntityEquivalent` in #18408. Leaving these defaults in place would result in a glaring inconsistency between these set collections and the others. Additionally, the current standard in the engine is for "entity" to mean `Entity`. APIs could be changed to accept `EntityEquivalent`, however that is a separate and contentious discussion. ## Solution Name these set collections `UniqueEntityEquivalent*`, and retain the `UniqueEntity*` name for an alias of the `Entity` case. While more verbose, this allows for all generics to be in proper order, full consistency between all set types*, and the "entity" name to be restricted to `Entity`. On top of that, `UniqueEntity*` now always have 1 generic less, when previously this was not enforced for the default case. *`UniqueEntityIter<I: Iterator<T: EntityEquivalent>>` is the sole exception to this. Aliases are unable to enforce bounds (`lazy_type_alias` is needed for this), so for this type, doing this split would be a mere suggestion, and in no way enforced. Iterator types are rarely ever named, and this specific one is intended to be aliased when it sees more use, like we do for the corresponding set collection iterators. Furthermore, the `EntityEquivalent` precursor `Borrow<Entity>` was used exactly because of such iterator bounds! Because of that, we leave it as is. While no migration guide for 0.15 users, for those that upgrade from main: `UniqueEntityVec<T>` -> `UniqueEntityEquivalentVec<T>` `UniqueEntitySlice<T>` -> `UniqueEntityEquivalentSlice<T>` `UniqueEntityArray<N, T>` -> `UniqueEntityEquivalentArray<T, N>`
1 parent 2771803 commit c9fb956

File tree

8 files changed

+815
-635
lines changed

8 files changed

+815
-635
lines changed

crates/bevy_ecs/src/entity/entity_set.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::{
1313
option, result,
1414
};
1515

16-
use super::{Entity, UniqueEntitySlice};
16+
use super::{Entity, UniqueEntityEquivalentSlice};
1717

1818
use bevy_platform_support::sync::Arc;
1919

@@ -432,20 +432,20 @@ impl<T, I: Iterator<Item: EntityEquivalent> + AsRef<[T]>> AsRef<[T]> for UniqueE
432432
}
433433

434434
impl<T: EntityEquivalent, I: Iterator<Item: EntityEquivalent> + AsRef<[T]>>
435-
AsRef<UniqueEntitySlice<T>> for UniqueEntityIter<I>
435+
AsRef<UniqueEntityEquivalentSlice<T>> for UniqueEntityIter<I>
436436
{
437-
fn as_ref(&self) -> &UniqueEntitySlice<T> {
437+
fn as_ref(&self) -> &UniqueEntityEquivalentSlice<T> {
438438
// SAFETY: All elements in the original slice are unique.
439-
unsafe { UniqueEntitySlice::from_slice_unchecked(self.iter.as_ref()) }
439+
unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked(self.iter.as_ref()) }
440440
}
441441
}
442442

443443
impl<T: EntityEquivalent, I: Iterator<Item: EntityEquivalent> + AsMut<[T]>>
444-
AsMut<UniqueEntitySlice<T>> for UniqueEntityIter<I>
444+
AsMut<UniqueEntityEquivalentSlice<T>> for UniqueEntityIter<I>
445445
{
446-
fn as_mut(&mut self) -> &mut UniqueEntitySlice<T> {
446+
fn as_mut(&mut self) -> &mut UniqueEntityEquivalentSlice<T> {
447447
// SAFETY: All elements in the original slice are unique.
448-
unsafe { UniqueEntitySlice::from_slice_unchecked_mut(self.iter.as_mut()) }
448+
unsafe { UniqueEntityEquivalentSlice::from_slice_unchecked_mut(self.iter.as_mut()) }
449449
}
450450
}
451451

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub mod unique_array;
6767
pub mod unique_slice;
6868
pub mod unique_vec;
6969

70-
pub use unique_array::UniqueEntityArray;
71-
pub use unique_slice::UniqueEntitySlice;
72-
pub use unique_vec::UniqueEntityVec;
70+
pub use unique_array::{UniqueEntityArray, UniqueEntityEquivalentArray};
71+
pub use unique_slice::{UniqueEntityEquivalentSlice, UniqueEntitySlice};
72+
pub use unique_vec::{UniqueEntityEquivalentVec, UniqueEntityVec};
7373

7474
use crate::{
7575
archetype::{ArchetypeId, ArchetypeRow},

0 commit comments

Comments
 (0)