let
The let
keyword is used to assign a value to a variable during run-time. It can only be used inside of a function and its value can be changed when declared as mutable.
Immutable
We can declare a variable that cannot have its value changed in the following way.
let foo = 5;
By default foo
is an immutable u64
with the value of 5
. This means that we can pass foo
around and its value can be read, but it cannot have its value changed from 5
to any other value.
Mutable
We can declare a variable that can have its value changed through the use of the mut
keyword.
let mut foo = 5;
foo = 6;