0%

For developers who’ve mastered the basics, this book is the next step on your way to professional-level programming in Rust. It covers everything you need to build and maintain larger code bases, write powerful and flexible applications and libraries, and confidently expand the scope and complexity of your projects.

Author Jon Gjengset takes you deep into the Rust programming language, dissecting core topics like ownership, traits, concurrency, and unsafe code. You’ll explore key concepts like type layout and trait coherence, delve into the inner workings of concurrent programming and asynchrony with async/await, and take a tour of the world of no_std programming. Gjengset also provides expert guidance on API design, testing strategies, and error handling, and will help develop your understanding of foreign function interfaces, object safety, procedural macros, and much more.

You'll learn:

•How to design reliable, idiomatic, and ergonomic Rust programs based on best principles
•Effective use of declarative and procedural macros, and the difference between them
•How asynchrony works in Rust – all the way from the Pin and Waker types used in manual implementations of Futures, to how async/await saves you from thinking about most of those words
•What it means for code to be unsafe, and best practices for writing and interacting with unsafe functions and traits
•How to organize and configure more complex Rust projects so that they integrate nicely with the rest of the ecosystem
•How to write Rust code that can interoperate with non-Rust libraries and systems, or run in constrained and embedded environments

Brimming with practical, pragmatic insights that you can immediately apply, Rust for Rustaceans helps you do more with Rust, while also teaching you its underlying mechanisms.

Table of Contents

  1. Title Page
  2. Copyright
  3. About the Author
  4. Foreword
  5. Preface
  6. Acknowledgments
  7. Introduction
  8. Chapter 1: Foundations
    1. Talking About Memory
    2. Memory Terminology
    3. Variables in Depth
    4. Memory Regions
    5. Ownership
    6. Borrowing and Lifetimes
    7. Shared References
    8. Mutable References
    9. Interior Mutability
    10. Lifetimes
    11. Summary
  9. Chapter 2: Types
    1. Types in Memory
    2. Alignment
    3. Layout
    4. Complex Types
    5. Dynamically Sized Types and Wide Pointers
    6. Traits and Trait Bounds
    7. Compilation and Dispatch
    8. Generic Traits
    9. Coherence and the Orphan Rule
    10. Trait Bounds
    11. Marker Traits
    12. Existential Types
    13. Summary
  10. Chapter 3: Designing Interfaces
    1. Unsurprising
    2. Naming Practices
    3. Common Traits for Types
    4. Ergonomic Trait Implementations
    5. Wrapper Types
    6. Flexible
    7. Generic Arguments
    8. Object Safety
    9. Borrowed vs. Owned
    10. Fallible and Blocking Destructors
    11. Obvious
    12. Documentation
    13. Type System Guidance
    14. Constrained
    15. Type Modifications
    16. Trait Implementations
    17. Hidden Contracts
    18. Summary
  11. Chapter 4: Error Handling
    1. Representing Errors
    2. Enumeration
    3. Opaque Errors
    4. Special Error Cases
    5. Propagating Errors
    6. Summary
  12. Chapter 5: Project Structure
    1. Features
    2. Defining and Including Features
    3. Using Features in Your Crate
    4. Workspaces
    5. Project Configuration
    6. Crate Metadata
    7. Build Configuration
    8. Conditional Compilation
    9. Versioning
    10. Minimum Supported Rust Version
    11. Minimal Dependency Versions
    12. Changelogs
    13. Unreleased Versions
    14. Summary
  13. Chapter 6: Testing
    1. Rust Testing Mechanisms
    2. The Test Harness
    3. #[cfg(test)]
    4. Doctests
    5. Additional Testing Tools
    6. Linting
    7. Test Generation
    8. Test Augmentation
    9. Performance Testing
    10. Summary
  14. Chapter 7: Macros
    1. Declarative Macros
    2. When to Use Them
    3. How They Work
    4. How to Write Declarative Macros
    5. Procedural Macros
    6. Types of Procedural Macros
    7. The Cost of Procedural Macros
    8. So You Think You Want a Macro
    9. How Do They Work?
    10. Summary
  15. Chapter 8: Asynchronous Programming
    1. What’s the Deal with Asynchrony?
    2. Synchronous Interfaces
    3. Multithreading
    4. Asynchronous Interfaces
    5. Standardized Polling
    6. Ergonomic Futures
    7. async/await
    8. Pin and Unpin
    9. Going to Sleep
    10. Waking Up
    11. Fulfilling the Poll Contract
    12. Waking Is a Misnomer
    13. Tasks and Subexecutors
    14. Tying It All Together with spawn
    15. Summary
  16. Chapter 9: Unsafe Code
    1. The unsafe Keyword
    2. Great Power
    3. Juggling Raw Pointers
    4. Calling Unsafe Functions
    5. Implementing Unsafe Traits
    6. Great Responsibility
    7. What Can Go Wrong?
    8. Validity
    9. Panics
    10. Casting
    11. The Drop Check
    12. Coping with Fear
    13. Manage Unsafe Boundaries
    14. Read and Write Documentation
    15. Check Your Work
    16. Summary
  17. Chapter 10: Concurrency (and Parallelism)
    1. The Trouble with Concurrency
    2. Correctness
    3. Performance
    4. Concurrency Models
    5. Shared Memory
    6. Worker Pools
    7. Actors
    8. Asynchrony and Parallelism
    9. Lower-Level Concurrency
    10. Memory Operations
    11. Atomic Types
    12. Memory Ordering
    13. Compare and Exchange
    14. The Fetch Methods
    15. Sane Concurrency
    16. Start Simple
    17. Write Stress Tests
    18. Use Concurrency Testing Tools
    19. Summary
  18. Chapter 11: Foreign Function Interfaces
    1. Crossing Boundaries with extern
    2. Symbols
    3. Calling Conventions
    4. Types Across Language Boundaries
    5. Type Matching
    6. Allocations
    7. Callbacks
    8. Safety
    9. bindgen and Build Scripts
    10. Summary
  19. Chapter 12: Rust Without the Standard Library
    1. Opting Out of the Standard Library
    2. Dynamic Memory Allocation
    3. The Rust Runtime
    4. The Panic Handler
    5. Program Initialization
    6. The Out-of-Memory Handler
    7. Low-Level Memory Accesses
    8. Misuse-Resistant Hardware Abstraction
    9. Cross-Compilation
    10. Summary
  20. Chapter 13: The Rust Ecosystem
    1. What’s Out There?
    2. Tools
    3. Libraries
    4. Rust Tooling
    5. The Standard Library
    6. Patterns in the Wild
    7. Index Pointers
    8. Drop Guards
    9. Extension Traits
    10. Crate Preludes
    11. Staying Up to Date
    12. What Next?
    13. Learn by Watching
    14. Learn by Doing
    15. Learn by Reading
    16. Learn by Teaching
    17. Summary
  21. Index
3.144.36.141