Skip to content

Commit

Permalink
Migrate to assert_is_system
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Jan 11, 2022
1 parent acf3d40 commit 030f3d1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ impl<'w, 's, T: Fetch<'w, 's>> Fetch<'w, 's> for OptionFetch<T> {
/// }
/// }
/// }
/// # IntoSystem::into_system(print_moving_objects_system);
/// # bevy_ecs::system::assert_is_system(print_moving_objects_system);
/// ```
#[derive(Clone)]
pub struct ChangeTrackers<T: Component> {
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where
/// println!("{} is looking lovely today!", name.name);
/// }
/// }
/// # IntoSystem::into_system(compliment_entity_system);
/// # bevy_ecs::system::assert_is_system(compliment_entity_system);
/// ```
pub struct With<T>(PhantomData<T>);

Expand Down Expand Up @@ -188,7 +188,7 @@ unsafe impl<T> ReadOnlyFetch for WithFetch<T> {}
/// println!("{} has no permit!", name.name);
/// }
/// }
/// # IntoSystem::into_system(no_permit_system);
/// # bevy_ecs::system::assert_is_system(no_permit_system);
/// ```
pub struct Without<T>(PhantomData<T>);

Expand Down Expand Up @@ -317,7 +317,7 @@ unsafe impl<T> ReadOnlyFetch for WithoutFetch<T> {}
/// println!("Entity {:?} got a new style or color", entity);
/// }
/// }
/// # IntoSystem::into_system(print_cool_entity_system);
/// # bevy_ecs::system::assert_is_system(print_cool_entity_system);
/// ```
pub struct Or<T>(pub T);

Expand Down Expand Up @@ -619,7 +619,7 @@ impl_tick_filter!(
/// }
/// }
///
/// # IntoSystem::into_system(print_add_name_component);
/// # bevy_ecs::system::assert_is_system(print_add_name_component);
/// ```
Added,
/// The [`FetchState`] of [`Added`].
Expand Down Expand Up @@ -662,7 +662,7 @@ impl_tick_filter!(
/// }
/// }
///
/// # IntoSystem::into_system(print_moving_objects_system);
/// # bevy_ecs::system::assert_is_system(print_moving_objects_system);
/// ```
Changed,
/// The [`FetchState`] of [`Changed`].
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'w, 's> Commands<'w, 's> {
/// // adds a single component to the entity
/// .insert(Label("hello world"));
/// }
/// # IntoSystem::into_system(example_system);
/// # bevy_ecs::system::assert_is_system(example_system);
/// ```
pub fn spawn<'a>(&'a mut self) -> EntityCommands<'w, 's, 'a> {
let entity = self.entities.reserve_entity();
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'w, 's> Commands<'w, 's> {
/// // or insert single components like this:
/// .insert(Label("hello world"));
/// }
/// # IntoSystem::into_system(example_system);
/// # bevy_ecs::system::assert_is_system(example_system);
/// ```
pub fn spawn_bundle<'a, T: Bundle>(&'a mut self, bundle: T) -> EntityCommands<'w, 's, 'a> {
let mut e = self.spawn();
Expand Down Expand Up @@ -188,7 +188,7 @@ impl<'w, 's> Commands<'w, 's> {
/// // adds a single component to the entity
/// .insert(Label("hello world"));
/// }
/// # IntoSystem::into_system(example_system);
/// # bevy_ecs::system::assert_is_system(example_system);
/// ```
#[track_caller]
pub fn entity<'a>(&'a mut self, entity: Entity) -> EntityCommands<'w, 's, 'a> {
Expand Down Expand Up @@ -232,7 +232,7 @@ impl<'w, 's> Commands<'w, 's> {
/// ),
/// ]);
/// # }
/// # IntoSystem::into_system(system);
/// # bevy_ecs::system::assert_is_system(system);
/// ```
pub fn spawn_batch<I>(&mut self, bundles_iter: I)
where
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'w, 's> Commands<'w, 's> {
/// high_score: 0,
/// });
/// # }
/// # IntoSystem::into_system(system);
/// # bevy_ecs::system::assert_is_system(system);
/// ```
pub fn insert_resource<T: Resource>(&mut self, resource: T) {
self.queue.push(InsertResource { resource })
Expand All @@ -304,7 +304,7 @@ impl<'w, 's> Commands<'w, 's> {
/// # fn system(mut commands: Commands) {
/// commands.remove_resource::<Scoreboard>();
/// # }
/// # IntoSystem::into_system(system);
/// # bevy_ecs::system::assert_is_system(system);
/// ```
pub fn remove_resource<T: Resource>(&mut self) {
self.queue.push(RemoveResource::<T> {
Expand Down Expand Up @@ -345,7 +345,7 @@ impl<'w, 's> Commands<'w, 's> {
/// },
/// });
/// }
/// # IntoSystem::into_system(add_combat_stats_system);
/// # bevy_ecs::system::assert_is_system(add_combat_stats_system);
/// ```
pub fn add<C: Command>(&mut self, command: C) {
self.queue.push(command);
Expand All @@ -369,7 +369,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// fn my_system(mut commands: Commands) {
/// let entity_id = commands.spawn().id();
/// }
/// # IntoSystem::into_system(my_system);
/// # bevy_ecs::system::assert_is_system(my_system);
/// ```
#[inline]
pub fn id(&self) -> Entity {
Expand Down Expand Up @@ -405,7 +405,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// defense: Defense(20),
/// });
/// }
/// # IntoSystem::into_system(add_combat_stats_system);
/// # bevy_ecs::system::assert_is_system(add_combat_stats_system);
/// ```
pub fn insert_bundle(&mut self, bundle: impl Bundle) -> &mut Self {
self.commands.add(InsertBundle {
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// commands.spawn().insert_bundle((Component1, Component2));
/// commands.spawn_bundle((Component1, Component2));
/// }
/// # IntoSystem::into_system(example_system);
/// # bevy_ecs::system::assert_is_system(example_system);
/// ```
pub fn insert(&mut self, component: impl Component) -> &mut Self {
self.commands.add(Insert {
Expand Down Expand Up @@ -479,7 +479,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// fn remove_combat_stats_system(mut commands: Commands, player: Res<PlayerEntity>) {
/// commands.entity(player.entity).remove_bundle::<CombatBundle>();
/// }
/// # IntoSystem::into_system(remove_combat_stats_system);
/// # bevy_ecs::system::assert_is_system(remove_combat_stats_system);
/// ```
pub fn remove_bundle<T>(&mut self) -> &mut Self
where
Expand Down Expand Up @@ -508,7 +508,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// fn convert_enemy_system(mut commands: Commands, enemy: Res<TargetEnemy>) {
/// commands.entity(enemy.entity).remove::<Enemy>();
/// }
/// # IntoSystem::into_system(convert_enemy_system);
/// # bevy_ecs::system::assert_is_system(convert_enemy_system);
/// ```
pub fn remove<T>(&mut self) -> &mut Self
where
Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> {
/// {
/// commands.entity(character_to_remove.entity).despawn();
/// }
/// # IntoSystem::into_system(remove_character_system);
/// # bevy_ecs::system::assert_is_system(remove_character_system);
/// ```
pub fn despawn(&mut self) {
self.commands.add(Despawn {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pub trait IntoSystem<In, Out, Params>: Sized {
/// In future, this method will be removed.
///
/// One valid use of this method is to assert that a given function is a valid system.
/// For this case, use `IntoSystem::into_system` instead.
/// For this case, use `bevy_ecs::system::assert_is_system` instead.
#[deprecated(
since = "0.6.0",
note = "In most cases, using `.system()` is no longer necessary, and so it can be removed"
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//! }
//! round.0 += 1;
//! }
//! # IntoSystem::into_system(update_score_system);
//! # bevy_ecs::system::assert_is_system(update_score_system);
//! ```
//!
//! # System ordering
Expand Down Expand Up @@ -82,6 +82,13 @@ pub use system::*;
pub use system_chaining::*;
pub use system_param::*;

pub fn assert_is_system<In, Out, Params, S: IntoSystem<In, Out, Params>>(sys: S) {
if false {
// Check it can be converted into a system
IntoSystem::into_system(sys);
}
}

#[cfg(test)]
mod tests {
use std::any::TypeId;
Expand Down
Loading

0 comments on commit 030f3d1

Please sign in to comment.