bevy icon indicating copy to clipboard operation
bevy copied to clipboard

SystemParamBuilder - Enable type inference of closure parameter when building dynamic systems

Open chescock opened this issue 1 year ago • 0 comments

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: SystemState build_system docs

Example

let system = (LocalBuilder(0u64), ParamBuilder::local::<u64>())
    .build_state(&mut world)
    .build_system(|a, b| *a + *b + 1);

chescock avatar Aug 19 '24 18:08 chescock