-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify trait hierarchy for
SystemParam
(#6865)
# 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> {} ```
- Loading branch information
Showing
10 changed files
with
318 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.