pub fn doubler_factory() -> Box<dyn Fn(i32) -> i32>
Expand description

Creates a function which doubles an integer.

Note that it doesn’t have Fn(i32) -> i32 as its return type, but rather Box<Fn(i32) -> i32. At present, functions have to be explicitly heap-allocated. If we tried to return just a Fn type, we’d end up in a tangled mess of lifetime and ownership (whether with a regular function, as here, or a closure as in doubler_closure_factory).