SteveMcQwark•

Why do you take the closure? The effect I can see it having is preventing multiple calls, which, since this is a Fn and not a FnOnce, I don't see why you'd do that. It also puts f in an invalid state, which doesn't seem right.

3
ASeriesOfTubers•
let opt_closure = closure as *mut Option<F>;

Hmm, does that seem right? It's not a pointer to an optional closure. Perhaps it should instead be a Option<&F>?

If I try to run the code as is it panicks, but this works:

let opt_closure = (closure as *const F).as_ref();
let res = opt_closure.unwrap()(a as i32, b as i32);
3
Kimundirust•

Yeah, I also wondered about that...

3
bjzabarust · gfx-rs•

Oh my gosh - the amount of pain I went through with glfw-rs' callbacks was astounding. Thank goodness for unboxed closures!

2
Blaenk•

Thanks again for this :)

1
mzabaluev•
1
AatchOPrust•

Well I pulled this pattern out of the standard library, so I can't take credit anyway.

1