bevy/crates
Christian Hughes c7ec456e50
Support systems that take references as input (#15184)
# Objective

- Fixes #14924
- Closes #9584

## Solution

- We introduce a new trait, `SystemInput`, that serves as a type
function from the `'static` form of the input, to its lifetime'd
version, similarly to `SystemParam` or `WorldQuery`.
- System functions now take the lifetime'd wrapped version,
`SystemInput::Param<'_>`, which prevents the issue presented in #14924
(i.e. `InRef<T>`).
- Functions for running systems now take the lifetime'd unwrapped
version, `SystemInput::Inner<'_>` (i.e. `&T`).
- Due to the above change, system piping had to be re-implemented as a
standalone type, rather than `CombinatorSystem` as it was previously.
- Removes the `Trigger<'static, E, B>` transmute in observer runner
code.

## Testing

- All current tests pass.
- Added additional tests and doc-tests.

---

## Showcase

```rust
let mut world = World::new();

let mut value = 2;

// Currently possible:
fn square(In(input): In<usize>) -> usize {
    input * input
}
value = world.run_system_once_with(value, square);

// Now possible:
fn square_mut(InMut(input): InMut<usize>) {
    *input *= *input;
}
world.run_system_once_with(&mut value, square_mut);

// Or:
fn square_ref(InRef(input): InRef<usize>) -> usize {
    *input * *input
}
value = world.run_system_once_with(&value, square_ref);
```

## Migration Guide

- All current explicit usages of the following types must be changed in
the way specified:
    - `SystemId<I, O>` to `SystemId<In<I>, O>`
    - `System<In = T>` to `System<In = In<T>>`
    - `IntoSystem<I, O, M>` to `IntoSystem<In<I>, O, M>`
    - `Condition<M, T>` to `Condition<M, In<T>>`
- `In<Trigger<E, B>>` is no longer a valid input parameter type. Use
`Trigger<E, B>` directly, instead.

---------

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2024-09-23 17:37:29 +00:00
..
bevy_a11y Reflected traits for resources and components: bevy_a11y (#15192) 2024-09-14 01:43:16 +00:00
bevy_animation Allow animation clips to animate arbitrary properties. (#15282) 2024-09-23 17:14:12 +00:00
bevy_app Support systems that take references as input (#15184) 2024-09-23 17:37:29 +00:00
bevy_asset Use crate: disqualified (#15372) 2024-09-23 17:34:17 +00:00
bevy_audio Reflect derived traits on all components and resources: bevy_audio (#15211) 2024-09-15 14:24:00 +00:00
bevy_color Fix floating point math (#15239) 2024-09-16 23:28:12 +00:00
bevy_core Unify crate-level preludes (#15080) 2024-09-08 17:10:57 +00:00
bevy_core_pipeline Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_derive Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_dev_tools Added HeadlessPlugins (#15203) (#15260) 2024-09-19 16:44:43 +00:00
bevy_diagnostic Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_dylib Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_ecs Support systems that take references as input (#15184) 2024-09-23 17:37:29 +00:00
bevy_encase_derive Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_gilrs Update gilrs requirement from 0.10.1 to 0.11.0 (#15245) 2024-09-16 23:34:04 +00:00
bevy_gizmos Reduce runtime panics through SystemParam validation (#15276) 2024-09-23 16:54:21 +00:00
bevy_gltf Allow animation clips to animate arbitrary properties. (#15282) 2024-09-23 17:14:12 +00:00
bevy_hierarchy Use crate: disqualified (#15372) 2024-09-23 17:34:17 +00:00
bevy_input Use of deprecated function in example for ButtonInput (#15221) 2024-09-15 15:22:39 +00:00
bevy_internal Spirv passthrough main (adopted, part deux) (#15352) 2024-09-22 14:51:14 +00:00
bevy_log Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_macro_utils Generate links to definition in source code pages on docs.rs and dev-docs.bevyengine.org (#12965) 2024-07-29 23:10:16 +00:00
bevy_math Fix floating point math (#15239) 2024-09-16 23:28:12 +00:00
bevy_mikktspace Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_pbr Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_picking Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_ptr Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_reflect Use crate: disqualified (#15372) 2024-09-23 17:34:17 +00:00
bevy_render Reduce runtime panics through SystemParam validation (#15276) 2024-09-23 16:54:21 +00:00
bevy_scene Rename push children to add children (#15196) 2024-09-16 23:16:04 +00:00
bevy_sprite feature gate picking backends (#15369) 2024-09-22 19:35:15 +00:00
bevy_state Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_tasks Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_text Zero fontsize panic workaround (#15371) 2024-09-23 17:31:50 +00:00
bevy_time Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_transform Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_ui Add the ability to control font smoothing (#15368) 2024-09-23 17:28:25 +00:00
bevy_utils move ShortName to bevy_reflect (#15340) 2024-09-21 20:52:46 +00:00
bevy_window Allow to expect (adopted) (#15301) 2024-09-20 19:16:42 +00:00
bevy_winit Log monitor and window information at startup in bevy_winit (#15377) 2024-09-23 17:36:16 +00:00