Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: John Arundel

About the book This friendly, supportive, yet challenging book will show you how master software engineers think, and guide you through the process of designing production-ready command-line tools in Rust, step by step. This book is aimed at those who have a little experience with Rust (or even a lot), and would now like to learn how to build good software with it. What is “good” software anyway? What would it look like in Rust? And how do we get there from here?

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide to building production-quality command-line tools in Rust, using test-driven development and real projects to show how experienced engineers think about design, error handling, and shipping. Best for readers with some Rust experience who want to move from "it compiles" to "it's good software." 【Book Arc】 - **Opening (~0%–9%)**: Sets up the philosophy and workflow—what "good" software means, how to set up a crate, and why testing comes first. Introduces the built-in test framework and the "bebugging" habit of deliberately breaking code to verify tests actually catch failures. - **Early (~9%–30%)**: Builds a line-counting tool and a logbook, covering command-line arguments, file I/O, error handling with `Result`, and the `clap` argument parser. Moves from prototypes to a published crate with documentation and metadata. - **Middle (~30%–52%)**: Tackles data persistence (a memo store with Serde/JSON), then a weather-fetching tool that introduces HTTP requests, JSON deserialization, mock testing with `httpmock`, and the newtype pattern for unit-safe temperatures. - **Late (~52%–70%)**: Explores running external commands via `std::process::Command`, building a Cargo runner and a timer/benchmark tool, with attention to `Instant`, unused-value warnings, and crate design. - **Ending (~70%–100%)**: Excerpts do not cover this range in detail; likely consolidates patterns, distribution, and final project polish. 【Key Takeaways】 - **Testing is the backbone of the book, not an afterthought** (Opening): every feature starts with a failing test, and "bebugging"—intentionally breaking code to confirm tests fail—is taught as a discipline. This matters because it builds the habit of trusting your test suite. - **Error handling is a design concern, not just syntax** (Early): the book walks through `Result`, `Option`, custom error types, and the difference between `io::Error` and application errors, showing how to present failures usefully to users. - **Start with the simplest thing that works, then refactor** (Early–Middle): prototypes like a rough line counter or a basic logbook are deliberately naive, then improved through tests and abstraction. This mirrors real development more than polished examples do. - **`clap` is powerful but optional** (Early): the book shows manual argument parsing first, then introduces `clap` with derive macros, emphasizing that you should understand what the framework does before adopting it. - **Data persistence needs careful type design** (Middle): moving from a raw `Vec` to a `Memo` struct with Serde serialization demonstrates how types encode domain logic and make serialization safe. - **Testability drives API design** (Middle): the weather tool's `get_weather` function is refactored into a provider abstraction with injectable base URLs specifically so it can be tested with `httpmock` instead of hitting a live API. - **Units and quantities deserve their own types** (Middle): the `Temperature` newtype pattern prevents mixing Celsius and Fahrenheit, a concrete example of making invalid states unrepresentable. - **External commands and timing are first-class tools** (Late): building a Cargo runner and a timer shows how Rust's standard library handles subprocesses and benchmarking, with practical warnings about unused values and `Instant`. 【Reading Tips】 - **Deep-read the testing chapters** (Opening–Early): the TDD workflow and bebugging technique are the book's core methodology and will pay off across every later project. - **Skim the early prototypes if you're experienced**: the "rough first draft" sections are intentionally naive; focus on the refactoring and test-driven improvements that follow. - **Pause on the weather tool's mock testing section** (Middle): this is the hardest conceptual jump—designing for testability with provider abstractions and injected URLs—and rewards careful reading. - **Try the exercises**: the book repeatedly says "Over to you" and provides practice tests; actually writing the code is where the lessons stick. - **Don't skip the documentation and publishing chapter** (Early): crate metadata, README, and doc comments are treated as design tools, not chores. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half to two-thirds of the book; the final chapters and any concluding material are not represented, so the Ending section is inferred rather than summarized.
Page 2
l failure messages . . . . . . . . . . . . . . . . . . . . . 22 Testing a function that prints . . . . . . . . . . . . . . . . . . . . . . . 22 A data‐orient...
View in text
Page 4
. . . . . . . . . . . . . . 70 Integration tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Our first integration test . . . . . . . . . ....
View in text
Page 6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Achievement unlocked: memos . . . . . . . . . . . . . . . . . . . . . 129 Creating a type . ....
View in text
Page 8
. . . . . . . . . . . . . 179 Mocking the real API . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Injecting the base URL . . . . . . . . . . . . ....
View in text
Page 9
tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Running dry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 Adding a...
View in text
Page 13
ere’s no point me trying to duplicate the same content here. Accordingly, I’ll assume you’ve read these chapters, but not necessarily that you’ve un‐ derstoo...
View in text
Page 18
e were to publish this crate now (by uploading it to crates.io, for example), the wider Rust community could enjoy the fruits of our labours. Any time they n...
View in text
Page 20
'always_fails' panicked at hello/src/lib.rs:10:5: oh no ... failures: always_fails test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered...
View in text
Tags
AI categories
RustProgrammingSoftware
Publisher: Bitfield Consulting
Publish Year: 2025
Language: English
Pages: 240
File Format: PDF
File Size: 2.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…