> 2 - no allocation : , does'nt the lambda closure need to be allocated somewhere ?
I expect it is embedded in the state machine structure. In Rust (and C++) lambdas/closures are "value types".
I expect it is embedded in the state machine structure. In Rust (and C++) lambdas/closures are "value types".
If you stick to the raw lambdas, however, the compiler knows the size and doesn't need to use the heap. Only problem is that their type can't be named. In C++, you can work around this with auto.
Without getting too much into it, Rust has a similar distinction between raw lambdas and Box<Fn(...)>. This library uses the former.