top | item 46333946

(no title)

schneems | 2 months ago

Wouldn't that also move any referenced variables too? Unlike the block example that would make this code not identical to what it's replacing.

discuss

order

pflanze|2 months ago

No, unless you ask for it via the `move` keyword in front of the closure.

This works fine: https://play.rust-lang.org/?version=stable&mode=debug&editio...

schneems|2 months ago

Thanks. I was a genuine question and you answered it well. For some reason I've internalized that closures can capture variables sometimes, but I guess I'm not sure the conditions in which that's true (or perhaps I've learned/mis-remembered the wrong lesson a long time ago.