November 2017
Intermediate to advanced
264 pages
5h 45m
English
Suppose we get a boost from swallowing a health pack and our energy rises to a value of 25. However, if we assign the value to the variable energy as follows:
energy = 25;
We get an error, as follows:
error: re-assignment of immutable variable `energy`.
What is wrong here?
Well, Rust applies programmer's wisdom here: a lot of bugs come from inadvertent or wrong changes of variables, so don't let code change a value unless you have deliberately allowed it!
If you want a mutable variable, because its value can change during code execution, you have ...
Read now
Unlock full access