Rust programming video tutorial (Advanced) – 025_ 1 Introduction to unsafe rust

Time:2021-9-15

Video address

Headline address:https://www.ixigua.com/i677586170644791348…
Station B address:https://www.bilibili.com/video/av81202308/

Source address

GitHub address:https://github.com/anonymousGiga/learn_rus…

Explanation content

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

Linghu rushed