Unsafe Engineering · 19 min · free with an account

Raw Pointers

Lesson preview · about 30%

Represent an address without borrow guarantees.

Core idea

Creating *const T or *mut T is safe; dereferencing one is unsafe because validity, alignment, initialization, and aliasing are now the programmer's proof obligations.

Start with the idea

Creating *const T or *mut T is safe; dereferencing one is unsafe because validity, alignment, initialization, and aliasing are now the programmer's proof obligations.

A raw pointer such as *const T or *mut T can represent a location without the safety guarantees that a normal Rust reference carries. Constructing one from a valid reference is safe. Dereferencing it requires unsafe because the compiler cannot prove that the pointed-to object is still alive, aligned, initialized, in bounds, and accessed under valid aliasing rules. A raw pointer may carry provenance information about its allocation; treating it as merely a numeric address can miss part of the memory model.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Macros & Systems Rust