Mastering Rust: Learn about memory safety, type system, concurrency, and the new features of Rust 2018 edition, 2/e (Paperback)

Rahul Sharma, Vesa Kaihlavirta




Become proficient in designing, developing and deploying effective software systems using the advanced constructs of Rust

Key Features

  • Improve your productivity using the latest version of Rust and write simpler and easier code
  • Understand Rust's immutability and ownership principle, expressive type system, safe concurrency
  • Deep dive into the new doamins of Rust like WebAssembly, Networking and Command line tools

Book Description

Rust is an empowering language that provides a rare combination of safety, speed, and zero-cost abstractions. Mastering Rust – Second Edition is filled with clear and simple explanations of the language features along with real-world examples, showing you how you can build robust, scalable, and reliable programs.

This second edition of the book improves upon the previous one and touches on all aspects that make Rust a great language. We have included the features from latest Rust 2018 edition such as the new module system, the smarter compiler, helpful error messages, and the stable procedural macros. You'll learn how Rust can be used for systems programming, network programming, and even on the web. You'll also learn techniques such as writing memory-safe code, building idiomatic Rust libraries, writing efficient asynchronous networking code, and advanced macros. The book contains a mix of theory and hands-on tasks so you acquire the skills as well as the knowledge, and it also provides exercises to hammer the concepts in.

After reading this book, you will be able to implement Rust for your enterprise projects, write better tests and documentation, design for performance, and write idiomatic Rust code.

What you will learn

  • Write generic and type-safe code by using Rust's powerful type system
  • How memory safety works without garbage collection
  • Know the different strategies in error handling and when to use them
  • Learn how to use concurrency primitives such as threads and channels
  • Use advanced macros to reduce boilerplate code
  • Create efficient web applications with the Actix-web framework
  • Use Diesel for type-safe database interactions in your web application

Who this book is for

The book is aimed at beginner and intermediate programmers who already have familiarity with any imperative language and have only heard of Rust as a new language. If you are a developer who wants to write robust, efficient and maintainable software systems and want to become proficient with Rust, this book is for you. It starts by giving a whirlwind tour of the important concepts of Rust and covers advanced features of the language in subsequent chapters using code examples that readers will find useful to advance their knowledge.

Table of Contents

  1. Getting started with Rust
  2. Managing projects with cargo
  3. Tests, documentation and benchmarks
  4. Types, generics and traits
  5. Memory management and safety
  6. Error handling
  7. Advanced Topics
  8. Concurrency
  9. Metaprogramming with Macros
  10. Unsafe Rust and foreign function interfaces
  11. Logging
  12. Network programming in Rust: Sync and Async IO
  13. Building web applications with Rust
  14. Interacting with databases in Rust
  15. Rust on the web using WebAssembly
  16. Gui development with Rust
  17. Debugging


成為精通 Rust 的設計、開發和部署有效軟體系統的專家


- 使用最新版本的 Rust 提高生產力,編寫更簡單易懂的程式碼
- 理解 Rust 的不可變性和擁有權原則、表達性的類型系統和安全的並發
- 深入探索 Rust 的新領域,如 WebAssembly、網絡和命令行工具


Rust 是一種提供安全性、速度和零成本抽象的強大語言。《精通 Rust - 第二版》以清晰簡明的說明語言特性和實際示例為特色,向您展示如何構建強大、可擴展和可靠的程式。

本書第二版改進了上一版的內容,涵蓋了使 Rust 成為優秀語言的所有方面。我們包含了最新的 Rust 2018 版本的功能,如新的模組系統、更智能的編譯器、有用的錯誤訊息和穩定的程序化宏。您將學習如何使用 Rust 進行系統程式設計、網絡程式設計,甚至在網絡上使用 Rust。您還將學習編寫安全的記憶體程式碼、構建符合慣用 Rust 標準的程式庫、編寫高效的非同步網絡程式碼和高級宏。本書結合了理論和實踐任務,讓您不僅獲得技能,還獲得知識,並提供練習來鞏固概念。

閱讀本書後,您將能夠在企業專案中實施 Rust、編寫更好的測試和文件、設計高效能程式,並編寫符合慣用 Rust 標準的程式碼。


- 使用 Rust 強大的類型系統編寫通用和類型安全的程式碼
- 理解無需垃圾回收的記憶體安全性
- 了解不同的錯誤處理策略及其適用時機
- 學習如何使用線程和通道等並發原語
- 使用高級宏減少樣板程式碼
- 使用 Actix-web 框架創建高效的網絡應用程式
- 在網絡應用程式中使用 Diesel 進行類型安全的資料庫互動


本書適合初學者和中級程式設計師,他們已經熟悉任何命令式語言,並且只聽說過 Rust 作為一種新語言。如果您是一位開發人員,想要編寫堅固、高效且易於維護的軟體系統,並且想要精通 Rust,那麼本書適合您。它首先快速介紹了 Rust 的重要概念,然後在後續章節中使用讀者會發現有用的程式碼示例介紹了語言的高級功能。


1. 開始使用 Rust
2. 使用 cargo 管理專案
3. 測試、文件和基準測試
4. 類型、泛型和特性
5. 記憶體管理和安全性
6. 錯誤處理
7. 高級主題
8. 並發
9. 使用宏進行元程式設計
10. 不安全的 Rust 和外部函式介面
11. 日誌
12. Rust 中的網絡程式設計:同步和非同步 IO
13. 使用 Rust 構建網絡應用程式
14. 在 Rust 中與資料庫互動
15. 使用 WebAssembly 在網絡上使用 Rust
16. 使用 Rust 進行 GUI 開發
17. 調試