|
1.
|
|
|
# Introduction
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-ffi.md:4 src/doc/guide-lifetimes.md:4
src/doc/guide-macros.md:13 src/doc/guide-plugin.md:28
src/doc/guide-tasks.md:4 src/doc/guide-unsafe.md:4
|
|
2.
|
|
|
% Writing Unsafe and Low-Level Code in Rust
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:2
|
|
3.
|
|
|
Rust aims to provide safe abstractions over the low-level details of the CPU and operating system, but sometimes one needs to drop down and write code at that level. This guide aims to provide an overview of the dangers and power one gets with Rust's unsafe subset.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:9
|
|
4.
|
|
|
Rust provides an escape hatch in the form of the `unsafe { ... }` block which allows the programmer to dodge some of the compiler's checks and do a wide range of operations, such as:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:13
|
|
5.
|
|
|
- dereferencing [raw pointers](#raw-pointers) - calling a function via FFI ([covered by the FFI guide](guide-ffi.html)) - casting between types bitwise (`transmute`, aka "reinterpret cast") - [inline assembly](#inline-assembly)
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:18
|
|
6.
|
|
|
Note that an `unsafe` block does not relax the rules about lifetimes of `&` and the freezing of borrowed data.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:21
|
|
7.
|
|
|
Any use of `unsafe` is the programmer saying "I know more than you" to the compiler, and, as such, the programmer should be very sure that they actually do know more about why that piece of code is valid. In general, one should try to minimize the amount of unsafe code in a code base; preferably by using the bare minimum `unsafe` blocks to build safe interfaces.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:28
|
|
8.
|
|
|
> **Note**: the low-level details of the Rust language are still in > flux, and there is no guarantee of stability or backwards > compatibility. In particular, there may be changes that do not cause > compilation errors, but do cause semantic changes (such as invoking > undefined behaviour). As such, extreme care is required.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:34
|
|
9.
|
|
|
# Pointers
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:36 src/doc/guide.md:3371
|
|
10.
|
|
|
## References
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-unsafe.md:38 src/doc/guide.md:3389
|