@@ -730,10 +730,9 @@ unsafe impl<'a, T: Resource> ReadOnlySystemParam for Res<'a, T> {}
730
730
731
731
// SAFETY: Res ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this Res
732
732
// conflicts with any prior access, an error will occur.
733
- unsafe impl < ' a , T : Resource > ResultfulSystemParam for Res < ' a , T > {
733
+ unsafe impl < ' a , T : Resource > OptionalSystemParam for Res < ' a , T > {
734
734
type State = ComponentId ;
735
735
type Item < ' w , ' s > = Res < ' w , T > ;
736
- type Error = SystemParamError < Self > ;
737
736
738
737
fn init_state ( world : & mut World , system_meta : & mut SystemMeta ) -> Self :: State {
739
738
let component_id = world. initialize_resource :: < T > ( ) ;
@@ -764,7 +763,7 @@ unsafe impl<'a, T: Resource> ResultfulSystemParam for Res<'a, T> {
764
763
system_meta : & SystemMeta ,
765
764
world : & ' w World ,
766
765
change_tick : u32 ,
767
- ) -> Result < Self :: Item < ' w , ' s > , < Self :: Item < ' w , ' s > as ResultfulSystemParam > :: Error > {
766
+ ) -> Option < Self :: Item < ' w , ' s > > {
768
767
world
769
768
. get_resource_with_ticks ( component_id)
770
769
. map ( |( ptr, ticks) | Res {
@@ -774,16 +773,14 @@ unsafe impl<'a, T: Resource> ResultfulSystemParam for Res<'a, T> {
774
773
last_change_tick : system_meta. last_change_tick ,
775
774
change_tick,
776
775
} )
777
- . ok_or ( SystemParamError :: default ( ) )
778
776
}
779
777
}
780
778
781
779
// SAFETY: Res ComponentId and ArchetypeComponentId access is applied to SystemMeta. If this Res
782
780
// conflicts with any prior access, a panic will occur.
783
- unsafe impl < ' a , T : Resource > ResultfulSystemParam for ResMut < ' a , T > {
781
+ unsafe impl < ' a , T : Resource > OptionalSystemParam for ResMut < ' a , T > {
784
782
type State = ComponentId ;
785
783
type Item < ' w , ' s > = ResMut < ' w , T > ;
786
- type Error = SystemParamError < Self > ;
787
784
788
785
fn init_state ( world : & mut World , system_meta : & mut SystemMeta ) -> Self :: State {
789
786
let component_id = world. initialize_resource :: < T > ( ) ;
@@ -817,7 +814,7 @@ unsafe impl<'a, T: Resource> ResultfulSystemParam for ResMut<'a, T> {
817
814
system_meta : & SystemMeta ,
818
815
world : & ' w World ,
819
816
change_tick : u32 ,
820
- ) -> Result < Self :: Item < ' w , ' s > , < Self :: Item < ' w , ' s > as ResultfulSystemParam > :: Error > {
817
+ ) -> Option < Self :: Item < ' w , ' s > > {
821
818
world
822
819
. get_resource_unchecked_mut_with_id ( component_id)
823
820
. map ( |value| ResMut {
@@ -829,7 +826,6 @@ unsafe impl<'a, T: Resource> ResultfulSystemParam for ResMut<'a, T> {
829
826
change_tick,
830
827
} ,
831
828
} )
832
- . ok_or ( SystemParamError :: default ( ) )
833
829
}
834
830
}
835
831
@@ -1735,6 +1731,7 @@ mod tests {
1735
1731
pub struct EncapsulatedParam < ' w > ( Res < ' w , PrivateResource > ) ;
1736
1732
1737
1733
#[ derive( SystemParam ) ]
1734
+ #[ system_param( optional) ]
1738
1735
pub struct OptionalParam < ' w > {
1739
1736
_r0 : Res < ' w , R < 0 > > ,
1740
1737
_r1 : Res < ' w , R < 1 > > ,
0 commit comments