1. Previously discussed in this section are secure rust, that is, the memory security guarantee enforced by rust at compile time. This kind of memory security guarantee will not be enforced, that is, unsafe rust.
2. There are two main reasons for unsafe rust:
(1) Static analysis is conservative in nature, which means that some code may be legal, but rust will also refuse. In this case, unsafe code can be used.
(2) Inherent insecurity of underlying computer hardware. If rust does not allow unsafe operations, some tasks cannot be completed at all.
3. Unsafe rust has super power
Rust will switch to unsafe rust through the unsafe keyword. Unsafe rust has the following super powers:
(1) Dereference bare pointer
(2) Call unsafe functions or methods
(3) Access or modify variable static variables
(4) Implement insecure trait
Note: unsafe does not close the borrowing checker or disable any other rust security check rules. It only provides the above functions that are not checked by the compiler for memory security. Unsafe does not mean that the code in the block must not be OK. It just means that the programmer should ensure security.
This work adoptsCC agreement, reprint must indicate the author and the link to this article