Advanced Rust
Unsafe Rust
Unsafe Superpowers
-
Dereference a raw pointer
- raw pointers can be immutable or mutable and are written as *const T and *mut T, respectively
-
Call an unsafe function or method
unsafe
function has requirements we need to uphold and Rust can’t guarantee we’ve met these requirements
unsafe fn dangerous() {} // unsafe function unsafe { dangerous(); // usage }
-
Access or modify a mutable static variable
-
Implement an unsafe trait
-
Access fields of unions