@@ -487,15 +487,18 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
487
487
/// # schedule.add_systems((system_1, system_2, system_3));
488
488
/// # schedule.run(&mut world);
489
489
/// ```
490
- pub fn sort < L : ReadOnlyQueryData < Item < ' w > : Ord > + ' w > (
490
+ pub fn sort < L : ReadOnlyQueryData + ' w > (
491
491
self ,
492
492
) -> QuerySortedIter <
493
493
' w ,
494
494
' s ,
495
495
D ,
496
496
F ,
497
497
impl ExactSizeIterator < Item = Entity > + DoubleEndedIterator + FusedIterator + ' w ,
498
- > {
498
+ >
499
+ where
500
+ for < ' lw > L :: Item < ' lw > : Ord ,
501
+ {
499
502
self . sort_impl :: < L > ( |keyed_query| keyed_query. sort ( ) )
500
503
}
501
504
@@ -541,15 +544,18 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
541
544
/// # schedule.add_systems((system_1));
542
545
/// # schedule.run(&mut world);
543
546
/// ```
544
- pub fn sort_unstable < L : ReadOnlyQueryData < Item < ' w > : Ord > + ' w > (
547
+ pub fn sort_unstable < L : ReadOnlyQueryData + ' w > (
545
548
self ,
546
549
) -> QuerySortedIter <
547
550
' w ,
548
551
' s ,
549
552
D ,
550
553
F ,
551
554
impl ExactSizeIterator < Item = Entity > + DoubleEndedIterator + FusedIterator + ' w ,
552
- > {
555
+ >
556
+ where
557
+ for < ' lw > L :: Item < ' lw > : Ord ,
558
+ {
553
559
self . sort_impl :: < L > ( |keyed_query| keyed_query. sort_unstable ( ) )
554
560
}
555
561
@@ -604,7 +610,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
604
610
/// ```
605
611
pub fn sort_by < L : ReadOnlyQueryData + ' w > (
606
612
self ,
607
- mut compare : impl FnMut ( & L :: Item < ' w > , & L :: Item < ' w > ) -> Ordering ,
613
+ mut compare : impl FnMut ( & L :: Item < ' _ > , & L :: Item < ' _ > ) -> Ordering ,
608
614
) -> QuerySortedIter <
609
615
' w ,
610
616
' s ,
@@ -636,7 +642,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
636
642
/// This will panic if `next` has been called on `QueryIter` before, unless the underlying `Query` is empty.
637
643
pub fn sort_unstable_by < L : ReadOnlyQueryData + ' w > (
638
644
self ,
639
- mut compare : impl FnMut ( & L :: Item < ' w > , & L :: Item < ' w > ) -> Ordering ,
645
+ mut compare : impl FnMut ( & L :: Item < ' _ > , & L :: Item < ' _ > ) -> Ordering ,
640
646
) -> QuerySortedIter <
641
647
' w ,
642
648
' s ,
@@ -688,7 +694,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
688
694
/// #[derive(Component)]
689
695
/// struct AvailableMarker;
690
696
///
691
- /// #[derive(Component, PartialEq, Eq, PartialOrd, Ord)]
697
+ /// #[derive(Component, PartialEq, Eq, PartialOrd, Ord, Copy, Clone )]
692
698
/// enum Rarity {
693
699
/// Common,
694
700
/// Rare,
@@ -716,7 +722,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
716
722
/// .sort_by_key::<EntityRef, _>(|entity_ref| {
717
723
/// (
718
724
/// entity_ref.contains::<AvailableMarker>(),
719
- /// entity_ref.get::<Rarity>()
725
+ /// entity_ref.get::<Rarity>().copied()
720
726
/// )
721
727
/// })
722
728
/// .rev()
@@ -728,7 +734,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
728
734
/// ```
729
735
pub fn sort_by_key < L : ReadOnlyQueryData + ' w , K > (
730
736
self ,
731
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
737
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
732
738
) -> QuerySortedIter <
733
739
' w ,
734
740
' s ,
@@ -761,7 +767,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
761
767
/// This will panic if `next` has been called on `QueryIter` before, unless the underlying `Query` is empty.
762
768
pub fn sort_unstable_by_key < L : ReadOnlyQueryData + ' w , K > (
763
769
self ,
764
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
770
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
765
771
) -> QuerySortedIter <
766
772
' w ,
767
773
' s ,
@@ -796,7 +802,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
796
802
/// This will panic if `next` has been called on `QueryIter` before, unless the underlying `Query` is empty.
797
803
pub fn sort_by_cached_key < L : ReadOnlyQueryData + ' w , K > (
798
804
self ,
799
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
805
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
800
806
) -> QuerySortedIter <
801
807
' w ,
802
808
' s ,
@@ -826,7 +832,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> QueryIter<'w, 's, D, F> {
826
832
/// This will panic if `next` has been called on `QueryIter` before, unless the underlying `Query` is empty.
827
833
fn sort_impl < L : ReadOnlyQueryData + ' w > (
828
834
self ,
829
- f : impl FnOnce ( & mut Vec < ( L :: Item < ' w > , NeutralOrd < Entity > ) > ) ,
835
+ f : impl FnOnce ( & mut Vec < ( L :: Item < ' _ > , NeutralOrd < Entity > ) > ) ,
830
836
) -> QuerySortedIter <
831
837
' w ,
832
838
' s ,
@@ -1334,7 +1340,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1334
1340
impl ExactSizeIterator < Item = Entity > + DoubleEndedIterator + FusedIterator + ' w ,
1335
1341
>
1336
1342
where
1337
- L :: Item < ' w > : Ord ,
1343
+ for < ' lw > L :: Item < ' lw > : Ord ,
1338
1344
{
1339
1345
self . sort_impl :: < L > ( |keyed_query| keyed_query. sort ( ) )
1340
1346
}
@@ -1392,7 +1398,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1392
1398
impl ExactSizeIterator < Item = Entity > + DoubleEndedIterator + FusedIterator + ' w ,
1393
1399
>
1394
1400
where
1395
- L :: Item < ' w > : Ord ,
1401
+ for < ' lw > L :: Item < ' lw > : Ord ,
1396
1402
{
1397
1403
self . sort_impl :: < L > ( |keyed_query| keyed_query. sort_unstable ( ) )
1398
1404
}
@@ -1449,7 +1455,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1449
1455
/// ```
1450
1456
pub fn sort_by < L : ReadOnlyQueryData + ' w > (
1451
1457
self ,
1452
- mut compare : impl FnMut ( & L :: Item < ' w > , & L :: Item < ' w > ) -> Ordering ,
1458
+ mut compare : impl FnMut ( & L :: Item < ' _ > , & L :: Item < ' _ > ) -> Ordering ,
1453
1459
) -> QuerySortedManyIter <
1454
1460
' w ,
1455
1461
' s ,
@@ -1480,7 +1486,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1480
1486
/// called on [`QueryManyIter`] before.
1481
1487
pub fn sort_unstable_by < L : ReadOnlyQueryData + ' w > (
1482
1488
self ,
1483
- mut compare : impl FnMut ( & L :: Item < ' w > , & L :: Item < ' w > ) -> Ordering ,
1489
+ mut compare : impl FnMut ( & L :: Item < ' _ > , & L :: Item < ' _ > ) -> Ordering ,
1484
1490
) -> QuerySortedManyIter <
1485
1491
' w ,
1486
1492
' s ,
@@ -1532,7 +1538,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1532
1538
/// #[derive(Component)]
1533
1539
/// struct AvailableMarker;
1534
1540
///
1535
- /// #[derive(Component, PartialEq, Eq, PartialOrd, Ord)]
1541
+ /// #[derive(Component, PartialEq, Eq, PartialOrd, Ord, Copy, Clone )]
1536
1542
/// enum Rarity {
1537
1543
/// Common,
1538
1544
/// Rare,
@@ -1562,7 +1568,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1562
1568
/// .sort_by_key::<EntityRef, _>(|entity_ref| {
1563
1569
/// (
1564
1570
/// entity_ref.contains::<AvailableMarker>(),
1565
- /// entity_ref.get::<Rarity>()
1571
+ // entity_ref.get::<Rarity>().copied ()
1566
1572
/// )
1567
1573
/// })
1568
1574
/// .rev()
@@ -1574,7 +1580,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1574
1580
/// ```
1575
1581
pub fn sort_by_key < L : ReadOnlyQueryData + ' w , K > (
1576
1582
self ,
1577
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
1583
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
1578
1584
) -> QuerySortedManyIter <
1579
1585
' w ,
1580
1586
' s ,
@@ -1606,7 +1612,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1606
1612
/// called on [`QueryManyIter`] before.
1607
1613
pub fn sort_unstable_by_key < L : ReadOnlyQueryData + ' w , K > (
1608
1614
self ,
1609
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
1615
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
1610
1616
) -> QuerySortedManyIter <
1611
1617
' w ,
1612
1618
' s ,
@@ -1640,7 +1646,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1640
1646
/// called on [`QueryManyIter`] before.
1641
1647
pub fn sort_by_cached_key < L : ReadOnlyQueryData + ' w , K > (
1642
1648
self ,
1643
- mut f : impl FnMut ( & L :: Item < ' w > ) -> K ,
1649
+ mut f : impl FnMut ( & L :: Item < ' _ > ) -> K ,
1644
1650
) -> QuerySortedManyIter <
1645
1651
' w ,
1646
1652
' s ,
@@ -1669,7 +1675,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
1669
1675
/// called on [`QueryManyIter`] before.
1670
1676
fn sort_impl < L : ReadOnlyQueryData + ' w > (
1671
1677
self ,
1672
- f : impl FnOnce ( & mut Vec < ( L :: Item < ' w > , NeutralOrd < Entity > ) > ) ,
1678
+ f : impl FnOnce ( & mut Vec < ( L :: Item < ' _ > , NeutralOrd < Entity > ) > ) ,
1673
1679
) -> QuerySortedManyIter <
1674
1680
' w ,
1675
1681
' s ,
@@ -2902,13 +2908,13 @@ mod tests {
2902
2908
{
2903
2909
let mut query = query_state
2904
2910
. iter_many_mut ( & mut world, [ id, id] )
2905
- . sort_by :: < & C > ( Ord :: cmp) ;
2911
+ . sort_by :: < & C > ( |l , r| Ord :: cmp ( l , r ) ) ;
2906
2912
while query. fetch_next ( ) . is_some ( ) { }
2907
2913
}
2908
2914
{
2909
2915
let mut query = query_state
2910
2916
. iter_many_mut ( & mut world, [ id, id] )
2911
- . sort_unstable_by :: < & C > ( Ord :: cmp) ;
2917
+ . sort_unstable_by :: < & C > ( |l , r| Ord :: cmp ( l , r ) ) ;
2912
2918
while query. fetch_next ( ) . is_some ( ) { }
2913
2919
}
2914
2920
{
0 commit comments