全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Closure, captured environment?

又称: closure · captured environment

Definition 9.2 University Computer Science — Year 2 · 第 9 章 — Functional Programming

A closure is a function value written inline, |x| x * rate, that may use variables of the scope where it is written. Those variables form its captured environment: the closure stores a reference to each, a mutable reference, or the value itself (move). By what its body does with them, a Rust closure implements Fn (it only reads them, and may be called any number of times), FnMut (it modifies them: called through a mutable borrow), or only FnOnce (it gives a captured value away: callable once).

A closure is a struct of its captures plus a function that receives that struct. The first two hold references into main’s frame and may not outlive it; the third holds its own copies.
A closure is a struct of its captures plus a function that receives that struct. The first two hold references into main’s frame and may not outlive it; the third holds its own copies.
在原文中阅读 →