Update docs.

This commit is contained in:
Stephen Chung
2020-12-16 14:57:28 +08:00
parent f8c14ba1c4
commit 95b8dcc623
15 changed files with 169 additions and 109 deletions

View File

@@ -61,8 +61,8 @@ r"
```
Constants Can be Modified via Rust
---------------------------------
Caveat - Constants Can be Modified via Rust
------------------------------------------
A custom type stored as a constant cannot be modified via script, but _can_ be modified via
a registered Rust function that takes a first `&mut` parameter - because there is no way for
@@ -76,9 +76,15 @@ x.increment(); // call 'increment' defined in Rust with '&mut' first parame
x == 43; // value of 'x' is changed!
fn double() {
this *= 2; // function squares 'this'
this *= 2; // function doubles 'this'
}
let y = 1; // 'y' is not constant and mutable
y.double(); // double it...
y == 2; // value of 'y' is changed as expected
x.double(); // <- error: cannot modify constant 'this'
x == 43; // value of 'x' is unchanged by script