@@ -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
@@ -489,6 +491,63 @@ unsafe impl<'a, D: ReadOnlyQueryData + 'static, F: QueryFilter + 'static> ReadOn
489
491
{
490
492
}
491
493
494
+ // SAFETY: Relevant query ComponentId and ArchetypeComponentId access is applied to SystemMeta. If
495
+ // this Query conflicts with any prior access, a panic will occur.
496
+ unsafe impl < ' world , ' state , D : QueryData + ' static , F : QueryFilter + ' static > SystemParam
497
+ for QueryNonEmpty < ' world , ' state , D , F >
498
+ {
499
+ type State = QueryState < D , F > ;
500
+ type Item < ' w , ' s > = QueryNonEmpty < ' w , ' s , D , F > ;
501
+
502
+ fn init_state ( world : & mut World , system_meta : & mut SystemMeta ) -> Self :: State {
503
+ Query :: < ' world , ' state , D , F > :: init_state ( world, system_meta)
504
+ }
505
+
506
+ unsafe fn new_archetype (
507
+ state : & mut Self :: State ,
508
+ archetype : & Archetype ,
509
+ system_meta : & mut SystemMeta ,
510
+ ) {
511
+ // SAFETY: Delegate to existing `SystemParam` implementations.
512
+ unsafe { Query :: < ' world , ' state , D , F > :: new_archetype ( state, archetype, system_meta) } ;
513
+ }
514
+
515
+ #[ inline]
516
+ unsafe fn get_param < ' w , ' s > (
517
+ state : & ' s mut Self :: State ,
518
+ system_meta : & SystemMeta ,
519
+ world : UnsafeWorldCell < ' w > ,
520
+ change_tick : Tick ,
521
+ ) -> Self :: Item < ' w , ' s > {
522
+ // SAFETY: Delegate to existing `SystemParam` implementations.
523
+ let query = unsafe {
524
+ Query :: < ' world , ' state , D , F > :: get_param ( state, system_meta, world, change_tick)
525
+ } ;
526
+ QueryNonEmpty ( query)
527
+ }
528
+
529
+ #[ inline]
530
+ unsafe fn validate_param (
531
+ state : & Self :: State ,
532
+ system_meta : & SystemMeta ,
533
+ world : UnsafeWorldCell ,
534
+ ) -> bool {
535
+ state. validate_world ( world. id ( ) ) ;
536
+ // SAFETY:
537
+ // - We have read-only access to the components accessed by query.
538
+ // - The world has been validated.
539
+ !unsafe {
540
+ state. is_empty_unsafe_world_cell ( world, system_meta. last_run , world. change_tick ( ) )
541
+ }
542
+ }
543
+ }
544
+
545
+ // SAFETY: QueryState is constrained to read-only fetches, so it only reads World.
546
+ unsafe impl < ' w , ' s , D : ReadOnlyQueryData + ' static , F : QueryFilter + ' static > ReadOnlySystemParam
547
+ for QueryNonEmpty < ' w , ' s , D , F >
548
+ {
549
+ }
550
+
492
551
/// A collection of potentially conflicting [`SystemParam`]s allowed by disjoint access.
493
552
///
494
553
/// Allows systems to safely access and interact with up to 8 mutually exclusive [`SystemParam`]s, such as
0 commit comments