November 2017
Intermediate to advanced
264 pages
5h 45m
English
In our previous example, m which had the value &n is the simplest form of pointer, called a reference (or borrowed pointer)--the variable m is a reference to the stack-allocated variable n and has type &i32 because it points to a value of type i32.
Here n is immutable, so m is also immutable; trying to change the value of n through m with *m = 7; for example, results in an error:
cannot assign to immutable borrowed content `*m`
Rust does not let you change an immutable variable via its pointer, contrary to C.
Because there is no danger of changing the value of n through a reference, multiple references to an immutable value are allowed, they can only ...
Read now
Unlock full access