@@ -3,7 +3,9 @@ use crate::{
33 bundle:: { Bundle , BundleId , BundleInfo , BundleInserter , DynamicBundle , InsertMode } ,
44 change_detection:: MutUntyped ,
55 component:: { Component , ComponentId , ComponentTicks , Components , Mutable , StorageType } ,
6- entity:: { Entities , Entity , EntityCloneBuilder , EntityLocation } ,
6+ entity:: {
7+ Entities , Entity , EntityBorrow , EntityCloneBuilder , EntityLocation , TrustedEntityBorrow ,
8+ } ,
79 event:: Event ,
810 observer:: Observer ,
911 query:: { Access , ReadOnlyQueryData } ,
@@ -17,7 +19,13 @@ use bevy_ptr::{OwningPtr, Ptr};
1719use bevy_utils:: { HashMap , HashSet } ;
1820#[ cfg( feature = "track_change_detection" ) ]
1921use core:: panic:: Location ;
20- use core:: { any:: TypeId , marker:: PhantomData , mem:: MaybeUninit } ;
22+ use core:: {
23+ any:: TypeId ,
24+ cmp:: Ordering ,
25+ hash:: { Hash , Hasher } ,
26+ marker:: PhantomData ,
27+ mem:: MaybeUninit ,
28+ } ;
2129use thiserror:: Error ;
2230
2331use super :: { unsafe_world_cell:: UnsafeEntityCell , Ref , ON_REMOVE , ON_REPLACE } ;
@@ -369,6 +377,44 @@ impl<'a> TryFrom<&'a FilteredEntityMut<'_>> for EntityRef<'a> {
369377 }
370378}
371379
380+ impl PartialEq for EntityRef < ' _ > {
381+ fn eq ( & self , other : & Self ) -> bool {
382+ self . entity ( ) == other. entity ( )
383+ }
384+ }
385+
386+ impl Eq for EntityRef < ' _ > { }
387+
388+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
389+ impl PartialOrd for EntityRef < ' _ > {
390+ /// [`EntityRef`]'s comparison trait implementations match the underlying [`Entity`],
391+ /// and cannot discern between different worlds.
392+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
393+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
394+ }
395+ }
396+
397+ impl Ord for EntityRef < ' _ > {
398+ fn cmp ( & self , other : & Self ) -> Ordering {
399+ self . entity ( ) . cmp ( & other. entity ( ) )
400+ }
401+ }
402+
403+ impl Hash for EntityRef < ' _ > {
404+ fn hash < H : Hasher > ( & self , state : & mut H ) {
405+ self . entity ( ) . hash ( state) ;
406+ }
407+ }
408+
409+ impl EntityBorrow for EntityRef < ' _ > {
410+ fn entity ( & self ) -> Entity {
411+ self . id ( )
412+ }
413+ }
414+
415+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
416+ unsafe impl TrustedEntityBorrow for EntityRef < ' _ > { }
417+
372418/// Provides mutable access to a single entity and all of its components.
373419///
374420/// Contrast with [`EntityWorldMut`], which allows adding and removing components,
@@ -869,6 +915,44 @@ impl<'a> TryFrom<&'a mut FilteredEntityMut<'_>> for EntityMut<'a> {
869915 }
870916}
871917
918+ impl PartialEq for EntityMut < ' _ > {
919+ fn eq ( & self , other : & Self ) -> bool {
920+ self . entity ( ) == other. entity ( )
921+ }
922+ }
923+
924+ impl Eq for EntityMut < ' _ > { }
925+
926+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
927+ impl PartialOrd for EntityMut < ' _ > {
928+ /// [`EntityMut`]'s comparison trait implementations match the underlying [`Entity`],
929+ /// and cannot discern between different worlds.
930+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
931+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
932+ }
933+ }
934+
935+ impl Ord for EntityMut < ' _ > {
936+ fn cmp ( & self , other : & Self ) -> Ordering {
937+ self . entity ( ) . cmp ( & other. entity ( ) )
938+ }
939+ }
940+
941+ impl Hash for EntityMut < ' _ > {
942+ fn hash < H : Hasher > ( & self , state : & mut H ) {
943+ self . entity ( ) . hash ( state) ;
944+ }
945+ }
946+
947+ impl EntityBorrow for EntityMut < ' _ > {
948+ fn entity ( & self ) -> Entity {
949+ self . id ( )
950+ }
951+ }
952+
953+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
954+ unsafe impl TrustedEntityBorrow for EntityMut < ' _ > { }
955+
872956/// A mutable reference to a particular [`Entity`], and the entire world.
873957///
874958/// This is essentially a performance-optimized `(Entity, &mut World)` tuple,
@@ -2969,6 +3053,44 @@ impl<'a> From<&'a EntityWorldMut<'_>> for FilteredEntityRef<'a> {
29693053 }
29703054}
29713055
3056+ impl PartialEq for FilteredEntityRef < ' _ > {
3057+ fn eq ( & self , other : & Self ) -> bool {
3058+ self . entity ( ) == other. entity ( )
3059+ }
3060+ }
3061+
3062+ impl Eq for FilteredEntityRef < ' _ > { }
3063+
3064+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
3065+ impl PartialOrd for FilteredEntityRef < ' _ > {
3066+ /// [`FilteredEntityRef`]'s comparison trait implementations match the underlying [`Entity`],
3067+ /// and cannot discern between different worlds.
3068+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
3069+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
3070+ }
3071+ }
3072+
3073+ impl Ord for FilteredEntityRef < ' _ > {
3074+ fn cmp ( & self , other : & Self ) -> Ordering {
3075+ self . entity ( ) . cmp ( & other. entity ( ) )
3076+ }
3077+ }
3078+
3079+ impl Hash for FilteredEntityRef < ' _ > {
3080+ fn hash < H : Hasher > ( & self , state : & mut H ) {
3081+ self . entity ( ) . hash ( state) ;
3082+ }
3083+ }
3084+
3085+ impl EntityBorrow for FilteredEntityRef < ' _ > {
3086+ fn entity ( & self ) -> Entity {
3087+ self . id ( )
3088+ }
3089+ }
3090+
3091+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
3092+ unsafe impl TrustedEntityBorrow for FilteredEntityRef < ' _ > { }
3093+
29723094/// Provides mutable access to a single entity and some of its components defined by the contained [`Access`].
29733095///
29743096/// To define the access when used as a [`QueryData`](crate::query::QueryData),
@@ -3258,6 +3380,44 @@ impl<'a> From<&'a mut EntityWorldMut<'_>> for FilteredEntityMut<'a> {
32583380 }
32593381}
32603382
3383+ impl PartialEq for FilteredEntityMut < ' _ > {
3384+ fn eq ( & self , other : & Self ) -> bool {
3385+ self . entity ( ) == other. entity ( )
3386+ }
3387+ }
3388+
3389+ impl Eq for FilteredEntityMut < ' _ > { }
3390+
3391+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
3392+ impl PartialOrd for FilteredEntityMut < ' _ > {
3393+ /// [`FilteredEntityMut`]'s comparison trait implementations match the underlying [`Entity`],
3394+ /// and cannot discern between different worlds.
3395+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
3396+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
3397+ }
3398+ }
3399+
3400+ impl Ord for FilteredEntityMut < ' _ > {
3401+ fn cmp ( & self , other : & Self ) -> Ordering {
3402+ self . entity ( ) . cmp ( & other. entity ( ) )
3403+ }
3404+ }
3405+
3406+ impl Hash for FilteredEntityMut < ' _ > {
3407+ fn hash < H : Hasher > ( & self , state : & mut H ) {
3408+ self . entity ( ) . hash ( state) ;
3409+ }
3410+ }
3411+
3412+ impl EntityBorrow for FilteredEntityMut < ' _ > {
3413+ fn entity ( & self ) -> Entity {
3414+ self . id ( )
3415+ }
3416+ }
3417+
3418+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
3419+ unsafe impl TrustedEntityBorrow for FilteredEntityMut < ' _ > { }
3420+
32613421/// Error type returned by [`TryFrom`] conversions from filtered entity types
32623422/// ([`FilteredEntityRef`]/[`FilteredEntityMut`]) to full-access entity types
32633423/// ([`EntityRef`]/[`EntityMut`]).
@@ -3361,6 +3521,44 @@ where
33613521 }
33623522}
33633523
3524+ impl < B : Bundle > PartialEq for EntityRefExcept < ' _ , B > {
3525+ fn eq ( & self , other : & Self ) -> bool {
3526+ self . entity ( ) == other. entity ( )
3527+ }
3528+ }
3529+
3530+ impl < B : Bundle > Eq for EntityRefExcept < ' _ , B > { }
3531+
3532+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
3533+ impl < B : Bundle > PartialOrd for EntityRefExcept < ' _ , B > {
3534+ /// [`EntityRefExcept`]'s comparison trait implementations match the underlying [`Entity`],
3535+ /// and cannot discern between different worlds.
3536+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
3537+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
3538+ }
3539+ }
3540+
3541+ impl < B : Bundle > Ord for EntityRefExcept < ' _ , B > {
3542+ fn cmp ( & self , other : & Self ) -> Ordering {
3543+ self . entity ( ) . cmp ( & other. entity ( ) )
3544+ }
3545+ }
3546+
3547+ impl < B : Bundle > Hash for EntityRefExcept < ' _ , B > {
3548+ fn hash < H : Hasher > ( & self , state : & mut H ) {
3549+ self . entity ( ) . hash ( state) ;
3550+ }
3551+ }
3552+
3553+ impl < B : Bundle > EntityBorrow for EntityRefExcept < ' _ , B > {
3554+ fn entity ( & self ) -> Entity {
3555+ self . id ( )
3556+ }
3557+ }
3558+
3559+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
3560+ unsafe impl < B : Bundle > TrustedEntityBorrow for EntityRefExcept < ' _ , B > { }
3561+
33643562/// Provides mutable access to all components of an entity, with the exception
33653563/// of an explicit set.
33663564///
@@ -3464,6 +3662,44 @@ where
34643662 }
34653663}
34663664
3665+ impl < B : Bundle > PartialEq for EntityMutExcept < ' _ , B > {
3666+ fn eq ( & self , other : & Self ) -> bool {
3667+ self . entity ( ) == other. entity ( )
3668+ }
3669+ }
3670+
3671+ impl < B : Bundle > Eq for EntityMutExcept < ' _ , B > { }
3672+
3673+ #[ expect( clippy:: non_canonical_partial_ord_impl) ]
3674+ impl < B : Bundle > PartialOrd for EntityMutExcept < ' _ , B > {
3675+ /// [`EntityMutExcept`]'s comparison trait implementations match the underlying [`Entity`],
3676+ /// and cannot discern between different worlds.
3677+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
3678+ self . entity ( ) . partial_cmp ( & other. entity ( ) )
3679+ }
3680+ }
3681+
3682+ impl < B : Bundle > Ord for EntityMutExcept < ' _ , B > {
3683+ fn cmp ( & self , other : & Self ) -> Ordering {
3684+ self . entity ( ) . cmp ( & other. entity ( ) )
3685+ }
3686+ }
3687+
3688+ impl < B : Bundle > Hash for EntityMutExcept < ' _ , B > {
3689+ fn hash < H : Hasher > ( & self , state : & mut H ) {
3690+ self . entity ( ) . hash ( state) ;
3691+ }
3692+ }
3693+
3694+ impl < B : Bundle > EntityBorrow for EntityMutExcept < ' _ , B > {
3695+ fn entity ( & self ) -> Entity {
3696+ self . id ( )
3697+ }
3698+ }
3699+
3700+ // SAFETY: This type represents one Entity. We implement the comparison traits based on that Entity.
3701+ unsafe impl < B : Bundle > TrustedEntityBorrow for EntityMutExcept < ' _ , B > { }
3702+
34673703fn bundle_contains_component < B > ( components : & Components , query_id : ComponentId ) -> bool
34683704where
34693705 B : Bundle ,
0 commit comments