rust里closure的move和Fn,FnMut,FnOnce

来源:互联网 发布:ps淘宝详情页制作视频 编辑:程序博客网 时间:2024/06/08 05:34

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.

0 0
原创粉丝点击