Help refactoring this line

source: learn-wgpu/lib.rs at master · sotrh/learn-wgpu · GitHub

I want to refactor this line:

event_loop.run(move |event, _, control_flow| match event {

into

let t = move | ... | { ... }
event_loop(t);

===

So the problem here is I now need to specify the types for event, _, control_flow. What we get here is:

event: Event<_, T>
_: EventLoopWindowTarget<T>,
control_flow: &mut ControlFlow

The problem: I can't figure out what the generic parameter T is.

Thanks!

You could change the working code to |event: (), _, control_flow| and once you try to compile it it should give a error "expected () got Event<...>"

It's not clearly stated, but T is actually a type you get to pick; it's the type of “user events” which can wake the winit event loop from another thread. If you're not using that feature, the default is (), so you would want the parameter types Event<'_, ()>, EventLoopWindowTarget<()>.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.