@@ -26,6 +26,8 @@ use core::{
26
26
ops:: { Deref , DerefMut } ,
27
27
} ;
28
28
29
+ use super :: QueryNonEmpty ;
30
+
29
31
/// A parameter that can be used in a [`System`](super::System).
30
32
///
31
33
/// # Derive
@@ -499,6 +501,63 @@ unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOn
499
501
{
500
502
}
501
503
504
+ // SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
505
+ // this Query conflicts with any prior access, a panic will occur.
506
+ unsafe impl < ' world , ' state , D : QueryData + ' static , F : QueryFilter + ' static > SystemParam
507
+ for QueryNonEmpty < ' world , ' state , D , F >
508
+ {
509
+ type State = QueryState < D , F > ;
510
+ type Item < ' w , ' s > = QueryNonEmpty < ' w , ' s , D , F > ;
511
+
512
+ fn init_state ( world : & mut World , system_meta : & mut SystemMeta ) -> Self :: State {
513
+ Query :: < ' world , ' state , D , F > :: init_state ( world, system_meta)
514
+ }
515
+
516
+ unsafe fn new_archetype (
517
+ state : & mut Self :: State ,
518
+ archetype : & Archetype ,
519
+ system_meta : & mut SystemMeta ,
520
+ ) {
521
+ // SAFETY: Delegate to existing `SystemParam` implementations.
522
+ unsafe { Query :: < ' world , ' state , D , F > :: new_archetype ( state, archetype, system_meta) } ;
523
+ }
524
+
525
+ #[ inline]
526
+ unsafe fn get_param < ' w , ' s > (
527
+ state : & ' s mut Self :: State ,
528
+ system_meta : & SystemMeta ,
529
+ world : UnsafeWorldCell < ' w > ,
530
+ change_tick : Tick ,
531
+ ) -> Self :: Item < ' w , ' s > {
532
+ // SAFETY: Delegate to existing `SystemParam` implementations.
533
+ let query = unsafe {
534
+ Query :: < ' world , ' state , D , F > :: get_param ( state, system_meta, world, change_tick)
535
+ } ;
536
+ QueryNonEmpty ( query)
537
+ }
538
+
539
+ #[ inline]
540
+ unsafe fn validate_param (
541
+ state : & Self :: State ,
542
+ system_meta : & SystemMeta ,
543
+ world : UnsafeWorldCell ,
544
+ ) -> bool {
545
+ state. validate_world ( world. id ( ) ) ;
546
+ // SAFETY:
547
+ // - We have read-only access to the components accessed by query.
548
+ // - The world has been validated.
549
+ !unsafe {
550
+ state. is_empty_unsafe_world_cell ( world, system_meta. last_run , world. change_tick ( ) )
551
+ }
552
+ }
553
+ }
554
+
555
+ // SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
556
+ unsafe impl < ' w , ' s , D : ReadOnlyQueryData + ' static , F : QueryFilter + ' static > ReadOnlySystemParam
557
+ for QueryNonEmpty < ' w , ' s , D , F >
558
+ {
559
+ }
560
+
502
561
/// A collection of potentially conflicting [`SystemParam`]s allowed by disjoint access.
503
562
///
504
563
/// Allows systems to safely access and interact with up to 8 mutually exclusive [`SystemParam`]s, such as
0 commit comments