mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
1e170d2e90
Add a `RunSystem` extension trait to allow for immediate execution of systems on a `World` for debugging and/or testing purposes. # Objective Fixes #6184 Initially, I made this CL as `ApplyCommands`. After a discussion with @cart , we decided a more generic implementation would be better to support all systems. This is the new revised CL. Sorry for the long delay! 😅 This CL allows users to do this: ```rust use bevy::prelude::*; use bevy::ecs::system::RunSystem; struct T(usize); impl Resource for T {} fn system(In(n): In<usize>, mut commands: Commands) -> usize { commands.insert_resource(T(n)); n + 1 } let mut world = World::default(); let n = world.run_system_with(1, system); assert_eq!(n, 2); assert_eq!(world.resource::<T>().0, 1); ``` ## Solution This is implemented as a trait extension and not included in any preludes to ensure it's being used consciously. Internally, it just initializes and runs a systems, and applies any deferred parameters all "in place". The trait has 2 functions (one of which calls the other by default): - `run_system_with` is the general implementation, which allows user to pass system input parameters - `run_system` is the ergonomic wrapper for systems with no input parameter (to avoid having the user pass `()` as input). ~~Additionally, this trait is also implemented for `&mut App`. I added this mainly for ergonomics (`app.run_system` vs. `app.world.run_system`).~~ (Removed based on feedback) --------- Co-authored-by: Pascal Hertleif <killercup@gmail.com> |
||
---|---|---|
.. | ||
bevy_a11y | ||
bevy_animation | ||
bevy_app | ||
bevy_asset | ||
bevy_audio | ||
bevy_core | ||
bevy_core_pipeline | ||
bevy_derive | ||
bevy_diagnostic | ||
bevy_dylib | ||
bevy_dynamic_plugin | ||
bevy_ecs | ||
bevy_ecs_compile_fail_tests | ||
bevy_encase_derive | ||
bevy_gilrs | ||
bevy_gizmos | ||
bevy_gltf | ||
bevy_hierarchy | ||
bevy_input | ||
bevy_internal | ||
bevy_log | ||
bevy_macro_utils | ||
bevy_macros_compile_fail_tests | ||
bevy_math | ||
bevy_mikktspace | ||
bevy_pbr | ||
bevy_ptr | ||
bevy_reflect | ||
bevy_reflect_compile_fail_tests | ||
bevy_render | ||
bevy_scene | ||
bevy_sprite | ||
bevy_tasks | ||
bevy_text | ||
bevy_time | ||
bevy_transform | ||
bevy_ui | ||
bevy_utils | ||
bevy_window | ||
bevy_winit |