Share constant variables for closures.

This commit is contained in:
Stephen Chung
2020-12-09 21:06:36 +08:00
parent dbee0eb0f5
commit 99dd7a6481
4 changed files with 24 additions and 27 deletions

View File

@@ -57,24 +57,6 @@ f.call(2) == 42;
```
Constants are Not Captured
--------------------------
Constants are never shared. Their values are simply cloned.
```rust
const x = 42; // constant variable 'x'
let f = |y| x += y; // constant 'x' is cloned and not captured
x.is_shared() == false; // 'x' is not shared
f.call(10); // the cloned copy of 'x' is changed
x == 42; // 'x' is not changed
```
Beware: Captured Variables are Truly Shared
------------------------------------------