liveBook · Manning

Chapter 2: Laying the foundation

What you will learn in chapter 2 of Rust Web Development

This introduction frames the chapter’s Rust foundations and their value for building adaptable web services.

After this chapter you will be able to

Section by section

Introduction

This introduction frames the chapter’s Rust foundations and their value for building adaptable web services.

Key terms: web framework, Rust ecosystem, crates, operating systems, allocate memory, execute functions

2.1 Following the Rust playbook

This section frames learning Rust as a practical process of using tools and documentation while accounting for the initial effort of strict typing.

Key terms: compiler, Clippy, docs.rs, strictly typed, types, unknown values

2.1.1 Modeling your resources with structs

This section models a question-and-answer service and introduces Rust structs, implementation blocks, and the New Type pattern.

Key terms: resources, models, Question, id, title, content, struct, fields, impl block, new

2.1.2 Understanding options

This section explains how Rust represents optional values and checks whether they are present.

Key terms: Option, Some, None, Option<Type>, match, is_some, pattern matching, destructuring, structs, enums

2.1.3 Using documentation to solve errors

This section uses a failing Question example to introduce Rust compiler errors, associated functions, and documentation navigation.

Key terms: associated functions, methods, &self, ::, compiler errors, QuestionId, &str, String, trait implementations, auto trait implementations

2.1.4 Handling strings in Rust

This section contrasts Rust’s owned, resizable String with read-only string slices and introduces the memory concepts behind them.

Key terms: String, &str, vector, u8, struct, parameter type, str, string slice, UTF-8, stack

2.1.5 Taking an excursion into moving, borrowing, and ownership

This section explains Rust ownership through String and &str assignments and two ways to pass a String to a function.

Key terms: ownership, garbage collector, String, &str, string slice, single-ownership principle, uninit, mut, push_str, variable shadowing

2.1.6 Using and implementing traits

This section uses traits, documentation, and compiler errors to fix and format a Question, then implements string conversion for its identifier.

Key terms: traits, shared behavior, generic, ToString, to_string, QuestionId, Option, Some, Vec, Display

2.1.7 Handling results

This section explains Rust’s Result type, how to handle success and failure, and when to use Result instead of Option.

Key terms: Result, Ok, Err, Result<T, E>, expect, unwrap, panic, match, Option, Question

2.2 Creating our web server

This section recaps Rust’s web-server building blocks and highlights how a framework and runtime shape an asynchronous server.

Key terms: runtime, asynchronous code blocks, Future, web framework, HTTP, TCP, UDP, route handlers, #[tokio::main], main

2.2.1 Handling multiple requests at once

This section explains how asynchronous execution helps servers handle multiple requests and identifies the components Rust provides for an asynchronous environment.

Key terms: blocking, runtime, yield, green threads, user space, kernel, kernel asynchronous read-and-write API, syntax, type, state

2.2.2 Rust’s asynchronous environment

This section introduces Rust’s async ecosystem, its runtime choices, and the basic roles of async, await, and Future.

Key terms: runtime, async kernel API, Tokio, async-std, Mio, async, await, Future, poll, Pending

2.2.3 Rust’s handling of async/await

This section introduces Rust’s async/await syntax through an HTTP request and explains dependency feature flags and the syntax’s state-machine model.

Key terms: feature flags, Cargo.toml, full, async, await, Future, runtime, reqwest::get, async/await, state machine

2.2.4 Using Rust’s Future type

This section explains the basic behavior of Rust futures, their trait-based flexibility, and the runtime’s role in polling them.

Key terms: Future, Output, poll, Pending, Ready, runtime, trait

2.2.5 Choosing a runtime

This section introduces Rust async runtimes, the choice of Tokio, and how an async network request moves through runtime components.

Key terms: runtime, Tokio, Future, polling, kernel, Mio, async, executor, poll, socket

2.2.6 Choosing a web framework

This section compares Rust web frameworks, explains the choice of Warp and its underlying stack, and incorporates a minimal Warp server into the project.

Key terms: Actix Web, Rocket, Warp, Axum, framework agnostic, Tokio, Hyper, runtime, route handlers, closure

2.3 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: Why Rust? Chapter 3: Create your first route handler →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.