Backend development

Stage 1 · Lesson 4 of 10

Result, Option and the ? operator

Your language and how HTTP works

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

  • BookFree
    The Rust Programming Language

    The Rust Project · Beginner

    The official book, free online: read ownership, enums, error handling and traits slowly

  • GuideFree
    Tokio Tutorial

    Tokio · Intermediate

    The official Tokio tutorial: tasks, shared state, channels and the async model Axum runs on

Practise

  • Small exercises that follow the book chapter by chapter, checked in your terminal

  • Your language track: small exercises with free mentor feedback on idiomatic code

Keep handy

  • Runnable examples to look up while you write: traits, generics, errors and Cargo

  • Read the HTTP overview, methods, headers and status code pages until they feel obvious

Also worth your time

Mark this stage as not done?