Unsafe Rust is dual to the safe part of the language and exists because computer hardware is inherently unsafe
The unsafe superpowers are turned on for specific blocks of
code using the unsafe keyword.
Note that
none of the previous safe features of the language are
disabled inside unsafe, we simply unlock new ones
unsafe is only a problem if everything in a program is
wrapped inside it
We must
keep unsafe blocks as close and isolated as possible,
this way:
unsafe block
unsafe gives us the ability to:
unionsThe Foreign Function Interface (FFI for friends) is a feature that allows our code to call/be called from other languages (link C or C++)
Foreign code is always unsafe
The FFI allows us to integrate Rust into other projects in other languages. Some small projects that do this are:
Our quick trip into unsafe stops only at the surface
For those who want to risk their soul and venture into the void, there is the Rustonomicon