Tous les livres

Professionnel

Applis À propos Coach Connexion Commencer la lecture

Computer Science · Glossaire

Qu'est-ce que « Closure, captured environment » ?

Aussi appelé : closure · captured environment

Definition 9.2 University Computer Science — Year 2 · Chapitre 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.
Lire dans le chapitre →