mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
1af73624fa
# Objective * Implementing a custom `SystemParam` by hand requires implementing three traits -- four if it is read-only. * The trait `SystemParamFetch<'w, 's>` is a workaround from before we had generic associated types, and is no longer necessary. ## Solution * Combine the trait `SystemParamFetch` with `SystemParamState`. * I decided to remove the `Fetch` name and keep the `State` name, since the former was consistently conflated with the latter. * Replace the trait `ReadOnlySystemParamFetch` with `ReadOnlySystemParam`, which simplifies trait bounds in generic code. --- ## Changelog - Removed the trait `SystemParamFetch`, moving its functionality to `SystemParamState`. - Replaced the trait `ReadOnlySystemParamFetch` with `ReadOnlySystemParam`. ## Migration Guide The trait `SystemParamFetch` has been removed, and its functionality has been transferred to `SystemParamState`. ```rust // Before impl SystemParamState for MyParamState { fn init(world: &mut World, system_meta: &mut SystemMeta) -> Self { ... } } impl<'w, 's> SystemParamFetch<'w, 's> for MyParamState { type Item = MyParam<'w, 's>; fn get_param(...) -> Self::Item; } // After impl SystemParamState for MyParamState { type Item<'w, 's> = MyParam<'w, 's>; // Generic associated types! fn init(world: &mut World, system_meta: &mut SystemMeta) -> Self { ... } fn get_param<'w, 's>(...) -> Self::Item<'w, 's>; } ``` The trait `ReadOnlySystemParamFetch` has been replaced with `ReadOnlySystemParam`. ```rust // Before unsafe impl ReadOnlySystemParamFetch for MyParamState {} // After unsafe impl<'w, 's> ReadOnlySystemParam for MyParam<'w, 's> {} ``` |
||
---|---|---|
.. | ||
src | ||
tests | ||
Cargo.toml | ||
README.md |
Compile fail tests for bevy_ecs
This crate is separate from bevy_ecs
and not part of the Bevy workspace in order to not fail crater
tests for Bevy. The tests assert on the exact compiler errors and can easily fail for new Rust versions due to updated compiler errors (e.g. changes in spans).
The CI
workflow executes these tests on the stable rust toolchain (see tools/ci).