<i>&gt; Hopefully the setup of closures that probably won&#x27;t be executed isnt&#x27;t too expensive. Do those require a heap allocation and release when not used, or is this all on the stack?</i><p>Creating a closure with |...| { ... } is literally as expensive as creating a tuple containing (references to) the variables it captures. That is, they&#x27;re on the stack by default like everything else in Rust, and there&#x27;s no implicit heap allocations. For more details, see, for instance, <a href="http:&#x2F;&#x2F;huonw.github.io&#x2F;blog&#x2F;2015&#x2F;05&#x2F;finding-closure-in-rust&#x2F;" rel="nofollow">http:&#x2F;&#x2F;huonw.github.io&#x2F;blog&#x2F;2015&#x2F;05&#x2F;finding-closure-in-rust&#x2F;</a> .<p><i>&gt; Rust has no idea which closure a function will call, if any.</i><p>It does. As my link above discusses, each closure has a unique type, allowing monomorphisation to kick in and hence the compiler can easily optimise and inline calls to closures (as long as the author of the closure-taking function doesn&#x27;t opt-in to only allowing virtual dispatch).