Loading tutorials
cargo run. The previous chapters covered why unsafe exists and what undefined behavior is. This chapter lists exactly 6 min readunsafe allows and what undefined behavior (UB) is. Examples use Rust 2024 and run with cargo run.5 min readunsafe blocks. It covers how to declare a function as unsafe, how to write down what callers must guarantee, and how to justify each call. Safe abstractions come in a later cha6 min readunsafe blocks and unsafe fn contracts. It covers how to hide unsafe code behind an interface that other code cannot misuse.5 min readstatic items, threads (std::thread::spawn), and the five unsafe operations from earlier in this tutorial. Here you will see what a static mut is, why every access needs unsafe, how the compiler now restricts references to it, and which safe types u6 min readimpl. That promise matters most for `S5 min readunsafe marks code whose safety the programmer must justify. You should also be able to build and run a Cargo project. The chapter covers how Rust declares and calls functions written in C, what the compiler chec5 min readCopy and Drop work, and what raw pointers and undefined behavior are from earlier chapters. By the end you will be able to declare a union, read and write its fields, and wrap one in a safe tagged type.6 min readunsafe fn and # Safety contracts from earlier chapters. You should also know how to run programs with Cargo. Examples need Rust 1.82 or newer, because they use unsafe extern style convent5 min readcargo run and cargo test. By the end you will be able to install Miri, run programs and tests under it, read its error repo5 min readunsafe block with a SAFETY comment and running cargo miri test. Here the question changes from "how do I write unsafe code" to "how do I arrange a proj7 min read