Skip to content

Commit b2661ea

Browse files
authored
Reorder impl to be the same as the trait (#10964)
# Objective - Make the implementation order consistent between all sources to fit the order in the trait. ## Solution - Change the implementation order.
1 parent c0489c3 commit b2661ea

File tree

12 files changed

+158
-158
lines changed

12 files changed

+158
-158
lines changed

crates/bevy_ecs/src/event.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,12 @@ impl<'a, E: Event> Iterator for EventIterator<'a, E> {
616616
self.iter.next().map(|(event, _)| event)
617617
}
618618

619-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
620-
self.iter.nth(n).map(|(event, _)| event)
619+
fn size_hint(&self) -> (usize, Option<usize>) {
620+
self.iter.size_hint()
621+
}
622+
623+
fn count(self) -> usize {
624+
self.iter.count()
621625
}
622626

623627
fn last(self) -> Option<Self::Item>
@@ -627,12 +631,8 @@ impl<'a, E: Event> Iterator for EventIterator<'a, E> {
627631
self.iter.last().map(|(event, _)| event)
628632
}
629633

630-
fn count(self) -> usize {
631-
self.iter.count()
632-
}
633-
634-
fn size_hint(&self) -> (usize, Option<usize>) {
635-
self.iter.size_hint()
634+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
635+
self.iter.nth(n).map(|(event, _)| event)
636636
}
637637
}
638638

@@ -696,16 +696,13 @@ impl<'a, E: Event> Iterator for EventIteratorWithId<'a, E> {
696696
}
697697
}
698698

699-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
700-
if let Some(EventInstance { event_id, event }) = self.chain.nth(n) {
701-
self.reader.last_event_count += n + 1;
702-
self.unread -= n + 1;
703-
Some((event, *event_id))
704-
} else {
705-
self.reader.last_event_count += self.unread;
706-
self.unread = 0;
707-
None
708-
}
699+
fn size_hint(&self) -> (usize, Option<usize>) {
700+
self.chain.size_hint()
701+
}
702+
703+
fn count(self) -> usize {
704+
self.reader.last_event_count += self.unread;
705+
self.unread
709706
}
710707

711708
fn last(self) -> Option<Self::Item>
@@ -717,13 +714,16 @@ impl<'a, E: Event> Iterator for EventIteratorWithId<'a, E> {
717714
Some((event, *event_id))
718715
}
719716

720-
fn count(self) -> usize {
721-
self.reader.last_event_count += self.unread;
722-
self.unread
723-
}
724-
725-
fn size_hint(&self) -> (usize, Option<usize>) {
726-
self.chain.size_hint()
717+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
718+
if let Some(EventInstance { event_id, event }) = self.chain.nth(n) {
719+
self.reader.last_event_count += n + 1;
720+
self.unread -= n + 1;
721+
Some((event, *event_id))
722+
} else {
723+
self.reader.last_event_count += self.unread;
724+
self.unread = 0;
725+
None
726+
}
727727
}
728728
}
729729

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,14 @@ pub type ROQueryItem<'w, D> = QueryItem<'w, <D as QueryData>::ReadOnly>;
278278
/// `update_component_access` and `update_archetype_component_access` do nothing.
279279
/// This is sound because `fetch` does not access components.
280280
unsafe impl WorldQuery for Entity {
281-
type Fetch<'w> = ();
282281
type Item<'w> = Entity;
282+
type Fetch<'w> = ();
283283
type State = ();
284284

285285
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
286286
item
287287
}
288288

289-
const IS_DENSE: bool = true;
290-
291289
unsafe fn init_fetch<'w>(
292290
_world: UnsafeWorldCell<'w>,
293291
_state: &Self::State,
@@ -296,6 +294,8 @@ unsafe impl WorldQuery for Entity {
296294
) -> Self::Fetch<'w> {
297295
}
298296

297+
const IS_DENSE: bool = true;
298+
299299
#[inline]
300300
unsafe fn set_archetype<'w>(
301301
_fetch: &mut Self::Fetch<'w>,
@@ -350,16 +350,14 @@ unsafe impl ReadOnlyQueryData for Entity {}
350350
/// This is sound because `update_component_access` and `update_archetype_component_access` set read access for all components and panic when appropriate.
351351
/// Filters are unchanged.
352352
unsafe impl<'a> WorldQuery for EntityRef<'a> {
353-
type Fetch<'w> = UnsafeWorldCell<'w>;
354353
type Item<'w> = EntityRef<'w>;
354+
type Fetch<'w> = UnsafeWorldCell<'w>;
355355
type State = ();
356356

357357
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
358358
item
359359
}
360360

361-
const IS_DENSE: bool = true;
362-
363361
unsafe fn init_fetch<'w>(
364362
world: UnsafeWorldCell<'w>,
365363
_state: &Self::State,
@@ -369,6 +367,8 @@ unsafe impl<'a> WorldQuery for EntityRef<'a> {
369367
world
370368
}
371369

370+
const IS_DENSE: bool = true;
371+
372372
#[inline]
373373
unsafe fn set_archetype<'w>(
374374
_fetch: &mut Self::Fetch<'w>,
@@ -432,16 +432,14 @@ unsafe impl ReadOnlyQueryData for EntityRef<'_> {}
432432

433433
/// SAFETY: The accesses of `Self::ReadOnly` are a subset of the accesses of `Self`
434434
unsafe impl<'a> WorldQuery for EntityMut<'a> {
435-
type Fetch<'w> = UnsafeWorldCell<'w>;
436435
type Item<'w> = EntityMut<'w>;
436+
type Fetch<'w> = UnsafeWorldCell<'w>;
437437
type State = ();
438438

439439
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
440440
item
441441
}
442442

443-
const IS_DENSE: bool = true;
444-
445443
unsafe fn init_fetch<'w>(
446444
world: UnsafeWorldCell<'w>,
447445
_state: &Self::State,
@@ -451,6 +449,8 @@ unsafe impl<'a> WorldQuery for EntityMut<'a> {
451449
world
452450
}
453451

452+
const IS_DENSE: bool = true;
453+
454454
#[inline]
455455
unsafe fn set_archetype<'w>(
456456
_fetch: &mut Self::Fetch<'w>,
@@ -530,21 +530,14 @@ impl<T> Copy for ReadFetch<'_, T> {}
530530
/// `update_component_access` adds a `With` filter for a component.
531531
/// This is sound because `matches_component_set` returns whether the set contains that component.
532532
unsafe impl<T: Component> WorldQuery for &T {
533-
type Fetch<'w> = ReadFetch<'w, T>;
534533
type Item<'w> = &'w T;
534+
type Fetch<'w> = ReadFetch<'w, T>;
535535
type State = ComponentId;
536536

537537
fn shrink<'wlong: 'wshort, 'wshort>(item: &'wlong T) -> &'wshort T {
538538
item
539539
}
540540

541-
const IS_DENSE: bool = {
542-
match T::Storage::STORAGE_TYPE {
543-
StorageType::Table => true,
544-
StorageType::SparseSet => false,
545-
}
546-
};
547-
548541
#[inline]
549542
unsafe fn init_fetch<'w>(
550543
world: UnsafeWorldCell<'w>,
@@ -568,6 +561,13 @@ unsafe impl<T: Component> WorldQuery for &T {
568561
}
569562
}
570563

564+
const IS_DENSE: bool = {
565+
match T::Storage::STORAGE_TYPE {
566+
StorageType::Table => true,
567+
StorageType::SparseSet => false,
568+
}
569+
};
570+
571571
#[inline]
572572
unsafe fn set_archetype<'w>(
573573
fetch: &mut ReadFetch<'w, T>,
@@ -686,21 +686,14 @@ impl<T> Copy for RefFetch<'_, T> {}
686686
/// `update_component_access` adds a `With` filter for a component.
687687
/// This is sound because `matches_component_set` returns whether the set contains that component.
688688
unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> {
689-
type Fetch<'w> = RefFetch<'w, T>;
690689
type Item<'w> = Ref<'w, T>;
690+
type Fetch<'w> = RefFetch<'w, T>;
691691
type State = ComponentId;
692692

693693
fn shrink<'wlong: 'wshort, 'wshort>(item: Ref<'wlong, T>) -> Ref<'wshort, T> {
694694
item
695695
}
696696

697-
const IS_DENSE: bool = {
698-
match T::Storage::STORAGE_TYPE {
699-
StorageType::Table => true,
700-
StorageType::SparseSet => false,
701-
}
702-
};
703-
704697
#[inline]
705698
unsafe fn init_fetch<'w>(
706699
world: UnsafeWorldCell<'w>,
@@ -723,6 +716,13 @@ unsafe impl<'__w, T: Component> WorldQuery for Ref<'__w, T> {
723716
}
724717
}
725718

719+
const IS_DENSE: bool = {
720+
match T::Storage::STORAGE_TYPE {
721+
StorageType::Table => true,
722+
StorageType::SparseSet => false,
723+
}
724+
};
725+
726726
#[inline]
727727
unsafe fn set_archetype<'w>(
728728
fetch: &mut RefFetch<'w, T>,
@@ -853,21 +853,14 @@ impl<T> Copy for WriteFetch<'_, T> {}
853853
/// `update_component_access` adds a `With` filter for a component.
854854
/// This is sound because `matches_component_set` returns whether the set contains that component.
855855
unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
856-
type Fetch<'w> = WriteFetch<'w, T>;
857856
type Item<'w> = Mut<'w, T>;
857+
type Fetch<'w> = WriteFetch<'w, T>;
858858
type State = ComponentId;
859859

860860
fn shrink<'wlong: 'wshort, 'wshort>(item: Mut<'wlong, T>) -> Mut<'wshort, T> {
861861
item
862862
}
863863

864-
const IS_DENSE: bool = {
865-
match T::Storage::STORAGE_TYPE {
866-
StorageType::Table => true,
867-
StorageType::SparseSet => false,
868-
}
869-
};
870-
871864
#[inline]
872865
unsafe fn init_fetch<'w>(
873866
world: UnsafeWorldCell<'w>,
@@ -890,6 +883,13 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
890883
}
891884
}
892885

886+
const IS_DENSE: bool = {
887+
match T::Storage::STORAGE_TYPE {
888+
StorageType::Table => true,
889+
StorageType::SparseSet => false,
890+
}
891+
};
892+
893893
#[inline]
894894
unsafe fn set_archetype<'w>(
895895
fetch: &mut WriteFetch<'w, T>,
@@ -1009,16 +1009,14 @@ impl<T: WorldQuery> Clone for OptionFetch<'_, T> {
10091009
/// This is sound because `update_component_access` and `update_archetype_component_access` add the same accesses as `T`.
10101010
/// Filters are unchanged.
10111011
unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
1012-
type Fetch<'w> = OptionFetch<'w, T>;
10131012
type Item<'w> = Option<T::Item<'w>>;
1013+
type Fetch<'w> = OptionFetch<'w, T>;
10141014
type State = T::State;
10151015

10161016
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
10171017
item.map(T::shrink)
10181018
}
10191019

1020-
const IS_DENSE: bool = T::IS_DENSE;
1021-
10221020
#[inline]
10231021
unsafe fn init_fetch<'w>(
10241022
world: UnsafeWorldCell<'w>,
@@ -1032,6 +1030,8 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
10321030
}
10331031
}
10341032

1033+
const IS_DENSE: bool = T::IS_DENSE;
1034+
10351035
#[inline]
10361036
unsafe fn set_archetype<'w>(
10371037
fetch: &mut OptionFetch<'w, T>,
@@ -1168,21 +1168,14 @@ pub struct Has<T>(PhantomData<T>);
11681168
/// `update_component_access` and `update_archetype_component_access` do nothing.
11691169
/// This is sound because `fetch` does not access components.
11701170
unsafe impl<T: Component> WorldQuery for Has<T> {
1171-
type Fetch<'w> = bool;
11721171
type Item<'w> = bool;
1172+
type Fetch<'w> = bool;
11731173
type State = ComponentId;
11741174

11751175
fn shrink<'wlong: 'wshort, 'wshort>(item: Self::Item<'wlong>) -> Self::Item<'wshort> {
11761176
item
11771177
}
11781178

1179-
const IS_DENSE: bool = {
1180-
match T::Storage::STORAGE_TYPE {
1181-
StorageType::Table => true,
1182-
StorageType::SparseSet => false,
1183-
}
1184-
};
1185-
11861179
#[inline]
11871180
unsafe fn init_fetch<'w>(
11881181
_world: UnsafeWorldCell<'w>,
@@ -1193,6 +1186,13 @@ unsafe impl<T: Component> WorldQuery for Has<T> {
11931186
false
11941187
}
11951188

1189+
const IS_DENSE: bool = {
1190+
match T::Storage::STORAGE_TYPE {
1191+
StorageType::Table => true,
1192+
StorageType::SparseSet => false,
1193+
}
1194+
};
1195+
11961196
#[inline]
11971197
unsafe fn set_archetype<'w>(
11981198
fetch: &mut Self::Fetch<'w>,
@@ -1408,14 +1408,12 @@ pub struct NopWorldQuery<D: QueryData>(PhantomData<D>);
14081408
/// `update_component_access` and `update_archetype_component_access` do nothing.
14091409
/// This is sound because `fetch` does not access components.
14101410
unsafe impl<D: QueryData> WorldQuery for NopWorldQuery<D> {
1411-
type Fetch<'w> = ();
14121411
type Item<'w> = ();
1412+
type Fetch<'w> = ();
14131413
type State = D::State;
14141414

14151415
fn shrink<'wlong: 'wshort, 'wshort>(_: ()) {}
14161416

1417-
const IS_DENSE: bool = D::IS_DENSE;
1418-
14191417
#[inline(always)]
14201418
unsafe fn init_fetch(
14211419
_world: UnsafeWorldCell,
@@ -1425,6 +1423,8 @@ unsafe impl<D: QueryData> WorldQuery for NopWorldQuery<D> {
14251423
) {
14261424
}
14271425

1426+
const IS_DENSE: bool = D::IS_DENSE;
1427+
14281428
#[inline(always)]
14291429
unsafe fn set_archetype(
14301430
_fetch: &mut (),

0 commit comments

Comments
 (0)