Stage 1 · Lesson 4 of 10
Result, Option and the ? operator
Rust has no exceptions for ordinary failures. A function that can fail returns Result<T, E>, which is either Ok with a value or Err with an error, and the caller must deal with both. The ? operator is the everyday tool: on an error it returns it to the caller straight away, and otherwise it hands you the value.
In a service, define one error enum with the , with variants such as NotFound and Database. In the stage you will map each variant to an status in one place. For startup code and scripts, anyhow lets you add context such as "loading config". Save panic! for bugs, not bad input.
Common trap.unwrap() and .expect() in request code: they turn a missing record or bad input into a crashed task instead of a or 422.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- BookFreeThe Rust Programming Language
The Rust Project · Beginner
The official book, free online: read ownership, enums, error handling and traits slowly
- GuideFreeTokio Tutorial
Tokio · Intermediate
The official Tokio tutorial: tasks, shared state, channels and the async model Axum runs on
Practise
Keep handy
Also worth your time
The DNS, TCP, TLS and HTTP steps behind every request your backend will handle