Rust Systems & Tokio (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What are Raw Pointers (`*const T` and `*mut T`) vs References (`&T` and `&mut T`)?
senior LevelrustAdvanced Internals
In Simple Words:
- References (
&T,&mut T): Always guaranteed by the compiler to be non-null, aligned, and pointing to valid data with bounded lifetimes. - Raw Pointers (
*const T,*mut T): Similar to C pointers:- Allowed to be
nullor dangling. - Ignore borrowing rules (can have multiple mutable raw pointers to the same address).
- Can only be dereferenced inside an
unsafeblock.
- Allowed to be