rust里closure的move和Fn,FnMut,FnOnce

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/varding/article/details/48214057

https://www.reddit.com/r/rust/comments/2ti57s/iron_framework_and_lifetime_problems_with/.

There seems to be two cases where a captured value is moved, copied or borrowed: when a closure is made (creating the struct with function pointer and the relevant environment) and when a closure is called. Did I understand right: move keyword means that a value is moved into the struct when a closure is CREATED. And Fn, FnMut and FnOnce decide how a value is moved/borrowed from the struct to the function body when a closure is CALLED?

That’s exactly right - they are orthogonal.
move || is just asking rustc to attempt to infer the kind of closure, referring to Fn/FnMut/FnOnce.

猜你喜欢

转载自blog.csdn.net/varding/article/details/48214057