Rust for Rustaceans: Idiomatic Programming for Experienced Developers

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Master professional-level coding in Rust. 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.

Author(s): Jon Gjengset
Publisher: No Starch Press
Year: 2021

Language: English
Commentary: Vector PDF
Pages: 280
City: San Francisco, CA
Tags: Multithreading; Concurrency; Asynchronous Programming; Parallel Programming; Memory Management; Rust; Error Handling; Testing; Unsafe Code

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