mirror of
https://github.com/bevyengine/bevy
synced 2024-11-27 07:00:18 +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> {} ``` |
||
---|---|---|
.. | ||
entity_ref_mut_lifetime_safety.rs | ||
entity_ref_mut_lifetime_safety.stderr | ||
query_exact_sized_iterator_safety.rs | ||
query_exact_sized_iterator_safety.stderr | ||
query_iter_combinations_mut_iterator_safety.rs | ||
query_iter_combinations_mut_iterator_safety.stderr | ||
query_iter_many_mut_iterator_safety.rs | ||
query_iter_many_mut_iterator_safety.stderr | ||
query_lifetime_safety.rs | ||
query_lifetime_safety.stderr | ||
query_to_readonly.rs | ||
query_to_readonly.stderr | ||
system_param_derive_readonly.rs | ||
system_param_derive_readonly.stderr | ||
system_query_get_lifetime_safety.rs | ||
system_query_get_lifetime_safety.stderr | ||
system_query_get_many_lifetime_safety.rs | ||
system_query_get_many_lifetime_safety.stderr | ||
system_query_get_many_mut_lifetime_safety.rs | ||
system_query_get_many_mut_lifetime_safety.stderr | ||
system_query_iter_lifetime_safety.rs | ||
system_query_iter_lifetime_safety.stderr | ||
system_query_iter_many_mut_lifetime_safety.rs | ||
system_query_iter_many_mut_lifetime_safety.stderr | ||
system_query_set_get_lifetime_safety.rs | ||
system_query_set_get_lifetime_safety.stderr | ||
system_query_set_iter_lifetime_safety.rs | ||
system_query_set_iter_lifetime_safety.stderr | ||
system_state_get_lifetime_safety.rs | ||
system_state_get_lifetime_safety.stderr | ||
system_state_iter_lifetime_safety.rs | ||
system_state_iter_lifetime_safety.stderr | ||
system_state_iter_mut_overlap_safety.rs | ||
system_state_iter_mut_overlap_safety.stderr | ||
world_query_derive.rs | ||
world_query_derive.stderr |