How can a closure using the `move` keyword create a FnMut closure?

前端 未结 2 869
陌清茗
陌清茗 2021-02-06 14:57

Up to this moment I thought that move |...| {...} would move variables inside a closure and the closure would implement only FnOnce, because you can mo

2条回答
  •  余生分开走
    2021-02-06 15:54

    Up to this moment I thought that move |...| {...} will move variables inside closure and closure will implement only FnOnce, because you can move vars only once.

    The variables are moved when the closure is created, not when it is invoked. Since you're only creating one closure, the move only happens once - regardless of how often map calls the function.

提交回复
热议问题