知识卡片

普通读书笔记卡 · 1395.b.1.c · 生成模型:未记录

闭包调用约束的三层

理解等级:高级

FnOnce 允许消耗闭包,FnMut 允许通过可变接收者反复调用,Fn 允许通过共享接收者反复调用。正文若移出非 Copy 捕获值,通常只能实现 FnOnce。move 声明的是捕获方式,若拥有的值在调用时只被借用,闭包仍可能实现 Fn。

相关卡片 [[move 闭包持有数据]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第13章 函数式语言特性:迭代器与闭包(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c13.xhtml`,块 0067) - 结论依据:原文按闭包正文是否移出或修改捕获值解释可实现的三类 trait。 - 原始内容:The way a closure captures and handles values from the environment affects which traits the closure implements, and traits are how functions and structs can specify what kinds of closures they can use. Closures will automatically implement one, two, or all three of these Fn traits, in an additive fashion, depending on how the closure’s body handles the values: