Skip to content

Commit

Permalink
implement SystemParam for SystemId
Browse files Browse the repository at this point in the history
  • Loading branch information
bilsen committed Aug 28, 2021
1 parent 0f89477 commit e553e4e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::{
ops::{Deref, DerefMut},
};

use super::SystemId;

/// A parameter that can be used in a [`System`](super::System).
///
/// # Derive
Expand Down Expand Up @@ -1157,6 +1159,39 @@ impl<'w, 's> SystemParamFetch<'w, 's> for SystemChangeTickState {
}
}

/// The [`SystemParamState`] of [`SystemIdState`].
pub struct SystemIdState;

// SAFE: Only reads internal system state
unsafe impl ReadOnlySystemParamFetch for SystemIdState {}

impl SystemParam for SystemId {
type Fetch = SystemIdState;
}

unsafe impl SystemParamState for SystemIdState {
type Config = ();

fn init(_world: &mut World, _system_meta: &mut SystemMeta, _config: Self::Config) -> Self {
Self {}
}

fn default_config() {}
}

impl<'w, 's> SystemParamFetch<'w, 's> for SystemIdState {
type Item = SystemId;

unsafe fn get_param(
_state: &'s mut Self,
system_meta: &SystemMeta,
_world: &'w World,
_change_tick: u32,
) -> Self::Item {
system_meta.id
}
}

macro_rules! impl_system_param_tuple {
($($param: ident),*) => {
impl<$($param: SystemParam),*> SystemParam for ($($param,)*) {
Expand Down

0 comments on commit e553e4e

Please sign in to comment.