liveBook · Manning

Chapter 24: Unfinished projects, continued

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

Introduces the final chapter’s three unfinished projects for readers to continue after finishing the book.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the final chapter’s three unfinished projects for readers to continue after finishing the book.

24.1 Web server word-guessing game

The section introduces a web-based word-guessing game and explains why the project will use Axum.

Key terms: word-guessing game, web server, command line, Rocket, Actix Web, Axum, Tokio, compilation units

24.1.1 Setup and first code

This section explains how to start a small local Axum server, connect GET routes to async handlers, extract a path value, and try the routes in a browser.

Key terms: axum::Router::new(), .route(), get, localhost, port, .serve(), extractors, Path<String>, async fn, async closures

24.1.2 Developing the code

The section develops the guessing game locally, then explains how an Axum request handler can access the game when the game and web server are joined.

Key terms: guessing game, command line, web server, Path<String>, GameApp, .with_state(), static

24.1.3 Further development and cleanup

The section finishes adapting the word-guessing game for a web server by storing the app as a static item, passing guesses to it, and returning the game’s output as a String.

Key terms: static item, const fn, allocation, get_res_from_static(), Mutex, static GAME, take_guess(), route, println!, format!

24.1.4 Over to you

Suggests ways to improve the finished web guessing game, especially its state handling and support for multiple players.

Key terms: global static, .with_state(), Arc<Mutex>, single game, axum_sessions, session per user, random suffix

24.2 Laser pointer

Introduces a pet-oriented laser-pointer project: a moving red dot in an egui GUI, made more interesting by varying its direction and speed.

Key terms: egui crate, GUI, laser pointer, random directions, random speeds

24.2.1 Setup and first code

Introduces the pieces needed to launch a minimal egui app and describes what its first window does.

Key terms: egui, eframe, widgets, closure, App trait, update(), eframe::run_native(), CreationContext, app struct, cargo run

24.2.2 Developing the code

This section explains egui’s screen coordinates and position types, then describes how the developing laser pointer behaves.

Key terms: Pos2, Rect, x-axis, y-axis, Vec2, laser pointer, mouse pointer

24.2.3 Further development and cleanup

The section explains how to make the laser pointer move erratically without requiring mouse-hover events.

Key terms: request_repaint(), .update(), hover event, invisible target, random movement, Speed, CrazyFast

24.2.4 Over to you

Suggests ways to extend the laser pointer by visualizing its movement target and offering different movement styles.

Key terms: laser pointer, invisible random target, settings, types of movement

24.3 Directory and file navigator

Introduces the final unfinished project: a directory and file navigator that will use egui to build a more complete UI.

24.3.1 Setup and first code

Introduces standard-library types and methods for finding the current directory, navigating paths, and reading directory entries.

Key terms: std::env::current_dir(), Result<PathBuf>, PathBuf, .push(), .pop(), std::fs::read_dir(), Result<ReadDir>, ReadDir, io::Result<DirEntry>, DirEntry

24.3.2 Developing the code

This section assembles a basic egui file navigator, shows how directory buttons change the current path, and identifies its remaining limitations.

Key terms: PathBuf, .push(), .pop(), .., RichText, directories, files, .unwrap(), system error

24.3.3 Further development and cleanup

The section explains how to build a clicked file’s path without changing the current directory and how to show its contents in a stable side panel.

Key terms: current_dir, PathBuf, array, Vec, file_content, SidePanel, CentralPanel, TextEdit, screen_rect(), .min_width()

24.3.4 Over to you

The section identifies unfinished parts of the directory and file navigator and suggests ways to improve its interface, code structure, and error reporting.

Key terms: scroll bar, panel on the right, typing area, whether text has been changed, if let, Result, DirectoryContent, Dir, File, Other

24.4 Summary

Concepts explained in this chapter

← Chapter 23: Unfinished projects: Projects for you to finish

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.