Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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...


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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: