Rust defines several kinds of pointers, each with a specific purpose. &T is a shared reference and there may be many duplicates of that shared reference. The owner of &T does not necessarily, own T and may not modify it. Shared references are immutable. Mutable references—written &mut T—also do not imply that the other &mut T owns T necessarily but the reference may be used to mutate T. There may be only one reference for any T with a &mut T. This complicates some code but means that Rust is able to prove that two variables do not overlap in memory, unlocking a variety of optimization opportunities absent from C/C++. Rust references are designed so that the compiler is able to prove the liveness of the referred to type: ...
Pointers to memory
Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.