liveBook · Manning

Chapter 19: More crates and async Rust

What you will learn in chapter 19 of Learn Rust in a Month of Lunches

The introduction previews reqwest and async Rust and explains why feature flags can help reduce compilation time.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction previews reqwest and async Rust and explains why feature flags can help reduce compilation time.

Key terms: feature flags, external crate, compilation time

19.1 The reqwest crate

Introduces making a GET request with reqwest and shows why its default Client leads to an async return type, prompting a look at the blocking Client.

Key terms: Client, .get(), IntoUrl, RequestBuilder, .send(), Future, async Rust, blocking Client, reqwest::blocking::Client

19.2 Feature flags

This section explains why crates use feature flags, how to enable reqwest’s blocking feature, and what its response provides.

Key terms: feature flags, Cargo.toml, Playground, blocking, cargo add reqwest --feature blocking, #[cfg(feature = "feature_name")], Response, .get(), .text(), Result<String>

19.3 Async Rust

Introduces async Rust as a way to keep other work moving while code waits for a slow operation, such as a server response.

Key terms: async Rust, block, thread, reqwest crate

19.3.1 Async basics

This section introduces a Future as a value that may become available later and explains what an async function actually returns.

Key terms: Future, Ready, Pending, Output, poll, async fn, fn, impl Future<Output = u8>

19.3.2 Checking whether a Future is ready

This section explains how polling checks a Future, why `.await` needs an async context, and why an async run time is needed to run async code.

Key terms: poll, Future, Poll::Pending, Poll::Ready(val), .await, async, polling, async fn main, async run time, Tokio

19.3.3 Using an async run time

This section shows how Tokio runs an async main function and how to use `.await` when calling async functions, including reqwest calls.

Key terms: Tokio, #[tokio::main], async fn main(), run time, .await, async fn, async block, regular functions, reqwest, Client

19.3.4 Some other details about async Rust

This section compares awaiting futures one by one with polling them together, then introduces macros for taking the first result or handling failures and notes where async Rust tools live.

Key terms: .await, join!, poll, future, select!, =>, timeout, try_join!, Err, external crates

19.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 18: Rust on your computer Chapter 20: A tour of the standard library →

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.