
Unsafe Rust Explained and What the Keyword Really Promises
A guide to unsafe Rust: what the keyword allows, the contract it creates, how to wrap it in a safe API, how to check it with Miri and where it is actually needed.
Everything you need to level up your coding skills.

A guide to unsafe Rust: what the keyword allows, the contract it creates, how to wrap it in a safe API, how to check it with Miri and where it is actually needed.

E0502 appears when you hold a reference into a value and then change that value. See the typical Vec case, why push is the danger, and four ways to resolve it.

In no_std a panic handler is mandatory. Compare panic-halt, panic-abort, panic-probe and a custom handler, and how panic = abort and the core panic machinery fit together.

A panic prints a message and one line of context. Set RUST_BACKTRACE to see the stack, find your frames in the noise and know what debug symbols change.

Accept and return JSON in Axum with the Json extractor and Serde: validate input, set status codes, handle bad bodies and avoid common content type mistakes.

Build a todo list CLI in Rust with clap subcommands, serde JSON storage, stable ids, atomic and durable saves, and a file lock that stops concurrent runs from losing items. Every claim measured.

E0499 means two mutable references to the same value were alive at once. Learn to spot which two, and fix it with scope, splitting or an index.

Make every Axum handler return Result with one AppError enum that implements IntoResponse, so the question mark works and clients get consistent JSON errors.

Rust error E0382 means a value was moved and then used again. Here are the five fixes in the order to try them, with the code for each.

Each layer of an application should speak its own error type. Convert at the boundary with From, keep causes for logs and map to HTTP codes only at the edge.

Copy is an implicit bitwise duplicate and Clone is an explicit call that can do real work. Know which of your types should have which, and what each costs.

Ownership is three rules the compiler checks for every value. This post builds a mental model from them and uses it to predict what compiles before you run the compiler.
We send one email when a new post is published. No spam.