diff --git a/src/Ch13_Functional_Language_Features_Iterators_and_Closures.md b/src/Ch13_Functional_Language_Features_Iterators_and_Closures.md index dc3e21c..eb92e18 100644 --- a/src/Ch13_Functional_Language_Features_Iterators_and_Closures.md +++ b/src/Ch13_Functional_Language_Features_Iterators_and_Closures.md @@ -285,9 +285,17 @@ fn main() { **Moving Captured Values Out of Closures and the `Fn` Traits** -一旦闭包捕获了引用,或捕获了环境中值的所有权(因此影响到被迁移 *进* 该闭包的任何物件),闭包主体中的代码,就会定义出闭包稍后被执行时,引用或值会发生什么(因此影响到被迁移 *出* 该闭包的相关项目,once a closure has captured a reference or captured ownership of a value from the environment where the closure is defined(thus affecting what, if anything, is moved *into* the closure), the code in the body of the closure defines what happens to the references or values when the closure is evaluated later(thus affecting what, if anything, is moved *out* of the closure))。闭包主体可执行以下任意操作:将捕获到的值迁移出闭包、修改捕获到的值、既不迁移也不修改该值,或以不捕获环境中任何东西开始。 +一旦闭包捕获了引用,或捕获了环境中值的所有权(因此影响到被迁移 *进* 该闭包的任何物件),闭包主体中的代码,就会定义出闭包稍后被执行时,引用或值会发生什么(因此影响到被迁移 *出* 该闭包的相关项目,once a closure has captured a reference or captured ownership of a value from the environment where the closure is defined(thus affecting what, if anything, is moved *into* the closure), the code in the body of the closure defines what happens to the references or values when the closure is evaluated later(thus affecting what, if anything, is moved *out* of the closure))。闭包主体可执行以下任意操作: -闭包捕获及处理环境中的值的方式,影响到闭包实现了哪个特质,而特质则是指函数与结构体,能够以怎样的方式,指明他们可以使用的闭包类别。依据闭包函数体处理环境中值的不同方式,闭包会以累加方式,自动实现一个、两个,或全部三个的这些 `Fn` 特质(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): +- 将捕获到的值迁移出闭包; + +- 修改捕获到的值; + +- 既不迁移也不修改该值; + +- 或以不捕获环境中任何东西开始。 + +闭包捕获进而处理环境中值的方式,影响到闭包会实现哪个特质,而特质则是指函数与结构体,能指明他们可使用闭包类别的方式。依据闭包主体处理环境中值的方式,闭包会以累加样式,自动实现一个、两个,或全部三个的 `Fn` 特质,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: 1. `FnOnce` 特质适用于那些可被调用一次的闭包。由于全部闭包都可被调用,因此他们都起码实现了这个特质。而由于将捕获到的值迁移出其函数体的闭包,只能被调用一次,因此这样的闭包将只要实现 `FnOnce`,而不会实现其他的那些 `Fn` 特质;