@@ -7,6 +7,7 @@ use slotmap::{KeyData, SecondaryMap, SlotMap};
7
7
use std:: {
8
8
any:: { type_name, Any , TypeId } ,
9
9
cell:: RefCell ,
10
+ cmp:: Ordering ,
10
11
fmt:: { self , Display } ,
11
12
hash:: { Hash , Hasher } ,
12
13
marker:: PhantomData ,
@@ -350,6 +351,18 @@ impl PartialEq for AnyEntity {
350
351
351
352
impl Eq for AnyEntity { }
352
353
354
+ impl Ord for AnyEntity {
355
+ fn cmp ( & self , other : & Self ) -> Ordering {
356
+ self . entity_id . cmp ( & other. entity_id )
357
+ }
358
+ }
359
+
360
+ impl PartialOrd for AnyEntity {
361
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
362
+ Some ( self . cmp ( other) )
363
+ }
364
+ }
365
+
353
366
impl std:: fmt:: Debug for AnyEntity {
354
367
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
355
368
f. debug_struct ( "AnyEntity" )
@@ -495,6 +508,18 @@ impl<T> PartialEq<WeakEntity<T>> for Entity<T> {
495
508
}
496
509
}
497
510
511
+ impl < T : ' static > Ord for Entity < T > {
512
+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
513
+ self . entity_id ( ) . cmp ( & other. entity_id ( ) )
514
+ }
515
+ }
516
+
517
+ impl < T : ' static > PartialOrd for Entity < T > {
518
+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
519
+ Some ( self . cmp ( other) )
520
+ }
521
+ }
522
+
498
523
/// A type erased, weak reference to a entity.
499
524
#[ derive( Clone ) ]
500
525
pub struct AnyWeakEntity {
@@ -599,6 +624,18 @@ impl PartialEq for AnyWeakEntity {
599
624
600
625
impl Eq for AnyWeakEntity { }
601
626
627
+ impl Ord for AnyWeakEntity {
628
+ fn cmp ( & self , other : & Self ) -> Ordering {
629
+ self . entity_id . cmp ( & other. entity_id )
630
+ }
631
+ }
632
+
633
+ impl PartialOrd for AnyWeakEntity {
634
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
635
+ Some ( self . cmp ( other) )
636
+ }
637
+ }
638
+
602
639
/// A weak reference to a entity of the given type.
603
640
#[ derive( Deref , DerefMut ) ]
604
641
pub struct WeakEntity < T > {
@@ -711,6 +748,18 @@ impl<T> PartialEq<Entity<T>> for WeakEntity<T> {
711
748
}
712
749
}
713
750
751
+ impl < T : ' static > Ord for WeakEntity < T > {
752
+ fn cmp ( & self , other : & Self ) -> Ordering {
753
+ self . entity_id ( ) . cmp ( & other. entity_id ( ) )
754
+ }
755
+ }
756
+
757
+ impl < T : ' static > PartialOrd for WeakEntity < T > {
758
+ fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
759
+ Some ( self . cmp ( other) )
760
+ }
761
+ }
762
+
714
763
#[ cfg( any( test, feature = "leak-detection" ) ) ]
715
764
static LEAK_BACKTRACE : std:: sync:: LazyLock < bool > =
716
765
std:: sync:: LazyLock :: new ( || std:: env:: var ( "LEAK_BACKTRACE" ) . map_or ( false , |b| !b. is_empty ( ) ) ) ;
0 commit comments