From Mastery to Expert Systems Craft
Introduction: The Expert’s Rust
- What This Book Assumes You Already Know
- Why Go Deeper: The Gap Between Competent and Expert
- The Mental Models That Matter Most
- How to Read This Book
Chapter 1: Advanced Ownership and Borrowing
- The Borrow Checker as a Constraint Solver
- Variance: Covariance, Contravariance and Invariance
- Drop Semantics and Destructor Order
- Complex Ownership Patterns Across Modules
- Pinning and Self-Referential Structures (Preview)
- Pitfalls: Use-After-Free in Safe Code and How to Avoid It
Chapter 2: The Trait System Deep Dive
- Higher-Ranked Trait Bounds (HRTBs) in Practice
- Associated Types Versus Generic Parameters
- Generic Associated Types (GATs): Problems They Solve
- Trait Objects and Dynamic Dispatch: When and How
- The Orphan Rule, Sealed Traits and API Design
- Supertraits, Negative Impls and Trait Resolution
- Pitfalls: Coherence Failures and Ambiguous Resolutions
Chapter 3: Type-Level Programming and Advanced Patterns
- The Type-State Pattern: Encoding State in Types
- Zero-Sized Types: PhantomData and Marker Traits
- Dynamically Sized Types (DSTs) Deep Dive
- The Newtype Pattern: Safety, ABI and Ergonomics
- Compile-Time Computation with Const Generics
- Pitfalls: Type Inference Limits and Error Explosion
Chapter 4: Interior Mutability and Smart Pointers
- The Philosophy of Interior Mutability
- RefCell, Cell and UnsafeCell: The Hierarchy
- Reference Counting: Rc, Arc, Weak and Cycles
- Building Custom Smart Pointers Safely
- Synchronization Primitives as Interior Mutability
- Pitfalls: Panics in Drop, Deadlocks and Memory Leaks
Chapter 5: Memory Layout and Representation
- Alignment, Padding and Struct Layout Rules
- #[repr] Attributes: C, Pack, Transparent and Integers
- Enum Memory Representation and Tagged Unions
- Fat Pointers and Metadata
- Cache-Friendly Data Layout and Performance
- Pitfalls: Undefined Behavior from Misaligned Access
Chapter 6: Concurrency Foundations - Send, Sync and Atomics
- Send and Sync: Auto Traits Explained
- Atomic Operations and Memory Ordering
- The Sequential Consistency Default and When to Relax It
- Building Thread-Safe Abstractions with Auto Traits
- Crossbeam and Advanced Concurrency Utilities
- Pitfalls: Data Races in Safe-Looking Code
Chapter 7: Advanced Concurrency and Lock-Free Patterns
- Lock-Free Versus Wait-Free: Definitions and Trade-offs
- Implementing a Lock-Free Stack in Rust
- Work-Stealing Queues and Parallel Task Scheduling
- Epoch-Based Reclamation (mimalloc, tikv-jemalloc patterns)
- Rayon, Scope-Based Parallelism and Data Parallels
- Pitfalls: ABA Problem, False Sharing and Priority Inversion
Chapter 8: Asynchronous Rust - Futures, Pinning and Executors
- The Future Trait: Polling Semantics from First Principles
- Pin and Why Self-Referential Futures Need It
- Executors: Work-Stealing, I/O and Task Scheduling
- Task Cancellation, JoinHandles and Scope Safety
- async/await Desugaring and Common Gotchas
- Pitfalls: Blocking the Executor, Unpin Bounds and Pin Projection
Chapter 9: Macros and Metaprogramming
- Declarative Macros: Pattern Matching in macro_rules!
- Hygiene, Span Preservation and Debugging Macros
- Procedural Derive Macros: Generating Boilerplate
- Attribute and Function-Like Procedural Macros
- Token Streams, Parsing with Syn and Quoting
- Pitfalls: Macro Explosion, Nightly Instability and IDE Support
Chapter 10: Unsafe Rust and Safe Abstractions
- The Contract of unsafe: What You Pledge to Uphold
- Raw Pointers: *const, *mut, Nullability and Dangling
- Aliasing Rules and the Strict Alias Rule in Rust
- Validity Requirements: When Is a Value “Valid”?
- Building Safe Abstractions Over Unsafe Code
- Pitfalls: Undefined Behavior That Compiles Cleanly
Chapter 11: FFI and Interoperability
- extern “C” Blocks and Calling Conventions
- Mapping C Types to Rust: Pointers, Structs and Unions
- Linking: Static, Dynamic and Build Scripts
- Callbacks and Function Pointers Across the Boundary
- Handling Errors and String Encoding in FFI
- Pitfalls: ABI Mismatches, Dangling Pointers and Lifetime Lies
Chapter 12: Custom Allocators and no_std Programming
- The Global Allocator Trait and Allocation Internals
- Arena Allocators and Bump Pointers
- Slab Allocators for Fixed-Size Objects
- no_std Essentials: Core, Alloc and Panic Handlers
- Embedded Rust Patterns: HALs, RTIC and Cortex-M
- Pitfalls: Stack Overflow, Allocation Failure and Missing Panics
Chapter 13: Performance Engineering and Profiling
- Benchmarking with criterion: Statistical Rigor Over Wall-Clock Time
- Profiling: From Sampling to Tracing
- Build Configuration: Optimization Levels, LTO and Codegen Units
- Profile-Guided Optimization (PGO)
- Cache Locality and Branch Prediction
- Monomorphization Costs and Mitigation Strategies
- Static Versus Dynamic Dispatch Performance
- Zero-Cost Abstractions in Practice
Chapter 14: Ecosystem, Architecture and Production Patterns
- Error Handling Architecture: anyhow for Applications, thiserror for Libraries
- Library Design: API Stability, Sealed Traits and the Orphan Rule
- Testing Strategies: Property-Based Testing and Fuzzing
- Documentation Practices for Rust Libraries
- Advanced Cargo: Workspaces, Features and Conditional Compilation
- Production Architectural Patterns