|
2 | 2 |
|
3 | 3 | As an introduction to this section, to borrow from [the official docs][unsafe],
|
4 | 4 | "one should try to minimize the amount of unsafe code in a code base." With that
|
5 |
| -in mind, let's get started! Unsafe blocks in Rust are used to bypass protections |
6 |
| -put in place by the compiler; specifically, there are four primary things that |
7 |
| -unsafe blocks are used for: |
| 5 | +in mind, let's get started! Unsafe annotations in Rust are used to bypass |
| 6 | +protections put in place by the compiler; specifically, there are four primary |
| 7 | +things that unsafe is used for: |
8 | 8 |
|
9 | 9 | * dereferencing raw pointers
|
10 |
| -* calling a function over FFI (but this is covered in [a previous |
11 |
| - chapter](std_misc/ffi.html) of the book) |
12 |
| -* calling functions which are `unsafe` |
13 |
| -* inline assembly |
| 10 | +* calling functions or methods which are `unsafe` (including calling a function |
| 11 | + over FFI, see [a previous chapter](std_misc/ffi.html) of the book) |
| 12 | +* accessing or modifying static mutable variables |
| 13 | +* implementing unsafe traits |
14 | 14 |
|
15 | 15 | ### Raw Pointers
|
16 | 16 | Raw pointers `*` and references `&T` function similarly, but references are
|
@@ -45,7 +45,7 @@ fn main() {
|
45 | 45 |
|
46 | 46 | unsafe {
|
47 | 47 | let my_slice: &[u32] = slice::from_raw_parts(pointer, length);
|
48 |
| - |
| 48 | +
|
49 | 49 | assert_eq!(some_vector.as_slice(), my_slice);
|
50 | 50 | }
|
51 | 51 | }
|
|
0 commit comments