bevy
bevy copied to clipboard
SystemParamBuilder - Enable type inference of closure parameter when building dynamic systems
Objective
When building a system from SystemParamBuilders and defining the system as a closure, the compiler should be able to infer the parameter types from the builder types.
Solution
Create methods for each arity that take an argument that implements both SystemParamFunction as well as FnMut(SystemParamItem<P>,...). The explicit FnMut constraint will allow the compiler to infer the necessary higher-ranked lifetimes along with the parameter types.
I wanted to show that this was possible, but I can't tell whether it's worth the complexity. It requires a separate method for each arity, which pollutes the docs a bit:
Example
let system = (LocalBuilder(0u64), ParamBuilder::local::<u64>())
.build_state(&mut world)
.build_system(|a, b| *a + *b + 1);