Rust 1.x Cookbook
Rust 1.x Cookbook
Summary:
Introduction
The book "Rust 1.x Cookbook" by Silvio Ghilardi was published in 2017 and is a collection of practical solutions for developers working with the Rust language. Unlike classic textbooks that sequentially introduce syntax and concepts, this book is built on the "cookbook" principle: each chapter contains specific tasks and ready-made recipes for completing them. This approach allows you to quickly move from theory to practice and immediately apply the acquired knowledge in real projects.
Rust is a modern systems language that combines high performance with guarantees of memory safety and thread safety. The book is focused on version 1.x, which is already stabilized and actively used in the industry. The volume is 360 pages, which is sufficient for an in-depth dive into the main aspects of the language, but without excessive academicism.
What the book is about
"Rust 1.x Cookbook" covers a wide range of topics — from basic constructs to advanced ecosystem features. Each chapter is dedicated to a specific area and contains from 5 to 15 recipes. Book structure:
- Chapter 1. Language Basics — variables, data types, control constructs, functions, ownership, and borrowing.
- Chapter 2. Structs and Enums — creating custom types, methods, traits, implementing polymorphism.
- Chapter 3. Error Handling — Result, Option, unwrap, expect, combinators, custom error types.
- Chapter 4. Collections and Iterators — vectors, hash maps, sets, iterator chains, performance.
- Chapter 5. Files and I/O — reading/writing files, working with paths, serialization (JSON, TOML, YAML).
- Chapter 6. Networking and HTTP — TCP/UDP sockets, HTTP clients and servers, working with URLs, HTML parsing.
- Chapter 7. Parallelism and Concurrency — threads, channels, mutexes, atomic operations, async/await (basic introduction).
- Chapter 8. Testing and Debugging — unit tests, integration tests, benchmarks, logging, profiling.
- Chapter 9. External Libraries and FFI — adding crates, calling C functions, creating bindings.
- Chapter 10. Building and Deployment — Cargo, workspace, profiles, cross-compilation, publishing crates.
Who this book is for
The book is intended for developers already familiar with the basics of programming but wishing to learn Rust from a practical side. It will be useful for:
- Beginning Rustaceans — those who have completed a basic tutorial and want to solidify their skills on real-world tasks.
- Experienced C/C++ programmers — for a quick transition to Rust and understanding its idioms.
- Developers transitioning from other languages — the book helps avoid common mistakes and master the specifics of memory management.
- Students and teachers — as a source of ready-made examples for lab work and course projects.
What the reader will learn
After reading the book, the reader will be able to:
- Confidently use the ownership, borrowing, and lifetimes system.
- Write efficient and safe programs without a garbage collector.
- Work with collections, iterators, and closures.
- Handle errors and create reliable applications.
- Interact with the file system and network.
- Implement multithreaded and asynchronous solutions.
- Test code and profile performance.
- Integrate Rust with existing C libraries.
- Configure builds and publish their own crates.
Strengths
- Practical focus — each recipe solves a specific problem, which accelerates learning.
- Clear structure — the book is broken down into well-organized chapters.