This repository contains sketches of code I used while following along a modified version of the Rust Programming Language Book.
This version contains an interactive component made of quizzes to aid in practicing the concepts in the book.
Each chapter, and most of the time each subchapter of the book, will have its own folder, appropriately identified; its contents are the result of me following the book along.
Some chapters, like 2, 12, and 20, leave to the reader the task of implementing small practical projects, which I will try to do in their entirety.
minigrep (Chapter 12)
Chapter 12 presents an extremely simple project for a grep that does not recurse directories,
and only searches the file specified as argument.
- Run
cargo testto verify the executable respects the case-insensitiveness flag - Run
cargo run -- to poem.txtto test it on the book's example file - Run
cargo run 2> error.txtto see that the executable prints errors to STDERR correctly
Mini Rust Web Server (Chapter 20)
In Chapter 20, a very simple web server running on localhost is built. It is capable of serving
concurrent requests, using a thread pool. The Rust async book does the same with async/await.
The below cargo commands assume pwd is that of chapter 20's project.
- Run
cargo runto start the server, and then:- Access
127.0.0.1:7878in a browser for the regular HTML being served - Access
127.0.0.1:7878/{anything}for the HTML served in case of error - Access
127.0.0.1:7878/sleepfor a page equal to the first, but only served after a 5 second delay
- Access
To check the server thread pool's concurrent behavior, duplicate a 127.0.0.1:7878/sleep tab while checking
STDOUT.
-
Run
cargo testto test the concurrent behavior ofThreadPool. There are currently two integration tests, that combine creating some files andstd::thread::sleepto checkcrate::ThreadPoolbehaves correctly. -
Run
cargo doc --opento read the package's documentation, with notes reflecting the content in chapter 20, and some of the author's own.