Raw pointers
In unsafe code blocks, Rust allows the use of a new kind of pointers called raw pointers. These pointers have no built-in security, but you can work with them with the same freedom as you would with C pointers. They are written as:
*const T
for a pointer to an immutable value, or typeT
*mut T
for a mutable pointer
These can point to invalid memory, and the memory resources need to be manually freed. This means that a raw pointer could inadvertently be used after freeing the memory it points to. Also, multiple concurrent threads have non-exclusive access to mutable raw pointers. Because you're not sure of its contents (at least, we have no compiler guarantee of valid content), dereferencing a raw pointer can also lead to program failure.
This is why dereferencing a raw pointer can only be done inside an unsafe block, as illustrated in the following code fragment:
// code from Chapter 10/code/raw_pointers.rs:
let p_raw: *const u32 = &10;
// let n = *p_raw; // compiler error...