For several consecutive years, Rust has been voted "most loved programming language" in Stack Overflow's annual developer survey. This open source systems programming language is now used for everything from game engines and operating systems to browser components and virtual reality simulation engines. But Rust is also an incredibly complex language with a notoriously difficult learning curve.
Rather than focusing on the language as a whole, this guide teaches Rust using a single small, complete, focused program in each chapter. Author Ken Youens-Clark shows you how to start, write, and test each of these programs to create a finished product. You'll learn how to handle errors in Rust, read and write files, and use regular expressions, Rust types, structs, and more.
Discover how to:
• Use Rust's standard libraries and data types such as numbers, strings, vectors, structs, Options, and Results to create command-line programs
• Write and test Rust programs and functions
• Read and write files, including stdin, stdout, and stderr
• Document and validate command-line arguments
• Write programs that fail gracefully
• Parse raw and delimited text manually, using regular expressions and Rust crates
• Use and control randomness
This book is a great way to practice writing Rust in real-world scenarios. Ken has laid out a path to build your skills in testing, using crates, and solving common problems. -- Carol Nichols, Cofounder, Integer 32, co-author of The Rust Programming Language (NoStarch, 2018)
Many people who start tinkering with Rust struggle to know how to apply it to their day-to-day work. Command Line Rust is an excellent remedy to this. It shows you how to build utilities that can demonstrate to you and your colleagues that Rust is worth learning. -- Tim McNamara, author of Rust In Action (Manning, 2021)
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on Rust primer that teaches the language by rebuilding classic Unix command-line tools one small, fully tested program at a time. Best for developers who know some programming but want practical Rust fluency through real, runnable utilities rather than abstract language theory.
【Book Arc】
- **Opening (~0%–10%)**: Sets up the book's philosophy — Rust's strict compiler and testing culture lead to more maintainable programs — and previews the project-based approach through the table of contents.
- **Early (~10%–30%)**: Establishes the toolchain and workflow: compiling with Cargo, using `$PATH`, pulling crates from crates.io, reading exit statuses, and writing unit and integration tests. Builds `true`/`false` and an `echo` clone to teach argument parsing and composability.
- **Early–Middle (~30%–45%)**: Moves into file I/O and text processing with `cat` and `head`, covering optional arguments that take values, parsing strings into numbers, `From`/`Into`/`as` conversions, iterators, and reading bytes versus characters.
- **Middle (~45%–60%)**: Deepens data handling with `wc` and related tools — counting lines, words, and bytes, handling STDIN, and learning why reading whole files into memory is dangerous versus streaming safely.
- **Late (~60%–90%)**: Tackles more complex utilities like `uniq`, `tail`, and `fortune`, introducing regular expressions, randomness, and more intricate argument validation and error handling.
- **Ending (~90%–100%)**: Consolidates the testing, crate usage, and problem-solving patterns built across the projects, reinforcing how to apply Rust to everyday tooling work.
【Key Takeaways】
- **Rust's compiler is a strict but valuable partner** (Early): The author frames type checking as preventing basic errors and argues that getting a program to compile usually means it works as intended.
- **Testing is woven into every project from the start** (Early): Unit tests, integration tests, and helper functions that compare program output against expected files are treated as core skills, not afterthoughts.
- **Exit statuses make programs composable** (Early): Correctly reporting success or failure lets tools chain with `&&` and other shell constructs, a hallmark of well-behaved CLI programs.
- **Argument parsing deserves real structure** (Early–Middle): Using crates like clap, the book shows how to define positional and optional arguments, validate them, and produce helpful error messages with nonzero exit codes.
- **File I/O has safe and dangerous paths** (Middle): Reading entire files into memory can crash on large inputs; the book contrasts this with streaming approaches using `take` and careful byte handling.
- **Bytes and characters are not interchangeable** (Middle): UTF-8 validity matters — `String::from_utf8_lossy` handles invalid sequences, and slicing bytes can panic on empty or multibyte inputs.
- **Type conversions and Option/Result chaining are everyday tools** (Middle): Patterns like `Option::map`, `transpose`, and `?` propagation appear repeatedly when parsing and validating configuration.
- **Each chapter is a complete, testable program** (Throughout): The project-based structure means every concept lands in a working utility, reinforcing retention through practice.
【Reading Tips】
- **Deep-read the testing chapters early**: The testing infrastructure (helper functions, expected-output files, `mk-outs.sh` scripts) is reused throughout, so investing time there pays off across every later project.
- **Skim the table of contents and chapter previews first**: They map which Unix tools are rebuilt and in what order, helping you decide which projects align with your goals.
- **Treat the "danger" examples as lessons, not templates**: The book deliberately shows unsafe file-reading patterns to explain why they fail — understand the reasoning rather than copying the code.
- **Run every program yourself**: The value is in compiling, testing, and debugging; reading alone misses the compiler-feedback loop that the book is built around.
- **Use the "Going Further" sections as stretch goals**: They suggest extensions after each project, useful if you want more practice beyond the guided solution.
【Coverage Limits】
The excerpts cover the book's opening philosophy, early toolchain setup, and several middle chapters (`cat`, `head`, `wc`, `tail`, `fortune`), but do not detail the full solutions or later chapters. Specific chapter counts, exact page ranges, and the complete list of projects beyond those mentioned are not fully covered.
Excerpt 1
thor of Rust In Action (Manning, 2021) Command-Line R ust A Project-Based Primer for Writing Rust CLIs Ken Youens-Clark Finding the Matching Lines of Input 2...
word will make this variable mutable so that it can change. Run the command and capture the output, which will be a Result. Verify that the result is an Ok v...
ividually and together, as regular files and through STDIN, using no flags and with the -n and -b flags. I capture all the outputs to various files in the te...
much worse, way to read the bytes from a file. You can read the entire file into a string, convert that into a vector of bytes, and then select the first num...
uts/empty.txt 1 9 48 tests/inputs/fox.txt 5 38 225 total I can count characters instead of bytes: $ cargo run -- -m tests/inputs/atlamal.txt 159 tests/inputs...
dir at this point: running 1 test test skips_bad_dir ... ok It will also handle unreadable directories, printing a message to STDERR: $ mkdir tests/inputs/ha...
in the preceding code is enclosed with r"" to denote a raw string, which prevents Rust from interpreting backslash-escaped values in the string. For instance...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Command-Line Rust A Project-Based Primer for Writing Rust CLIs (Ken Youens-Clark)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Command-Line Rust A Project-Based Primer for Writing Rust CLIs (Ken Youens-Clark)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment