Alle boeken

Professioneel

Apps Over Coach Inloggen Begin met lezen

Computer Science · Begrippenlijst

Wat is Closure, captured environment?

Ook bekend als: closure · captured environment

Definition 9.2 University Computer Science — Year 2 · Hoofdstuk 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.
Lees in het hoofdstuk →