This is a variation of what @thinkrapido implemented in https://github.com/nannou-org/nannou/pull/899 (and is based on it), but it stores closures in Box instead of Arc (which was already done in #815 for WASM support), and allows nannou consumers to pass closures directly to Builder methods, without wrapping them in Arc or using a macro.
To achieve that in a convenient way, it uses the trait_set macro, which enables us to use trait aliases without requiring nightly Rust. That's more convenient because it allows us to do e.g. trait ModelFn<Model> = 'static + Fn(&App) -> Model. Everything done here can be achieved without it, but we'd need to inline the definition of function types everywhere instead of importing aliases.
Here's an example of what we can achieve when Builder methods accept closures:
This is a variation of what @thinkrapido implemented in https://github.com/nannou-org/nannou/pull/899 (and is based on it), but it stores closures in
Box
instead ofArc
(which was already done in #815 for WASM support), and allows nannou consumers to pass closures directly toBuilder
methods, without wrapping them inArc
or using a macro.To achieve that in a convenient way, it uses the trait_set macro, which enables us to use trait aliases without requiring nightly Rust. That's more convenient because it allows us to do e.g.
trait ModelFn<Model> = 'static + Fn(&App) -> Model
. Everything done here can be achieved without it, but we'd need to inline the definition of function types everywhere instead of importing aliases.Here's an example of what we can achieve when
Builder
methods accept closures:This closes #793