Programming with Rust

Book description

Make Rust a key tool in your arsenal, and access one of the industry's fastest-growing areas of opportunity.

Rust's exciting innovations have made it the most loved programming language in Stack Overflow's influential survey for five straight years--but its steep learning curve has made many other developers reluctant to dive in. Now, with a growing commitment to Rust from many of the world's leading development organizations, it's the perfect time to start--especially now that there's an up-to-date, accessible, example-rich book to guide you.

In Programming with Rust, long-time enterprise developer Donis Marshall has made Rust easier to understand than ever, with a guide expertly organized into short, bite-sized chapters that bring you up-to-speed fast. Written for developers at all levels, Marshall starts with the absolute basics, and thoroughly demystifies the Rust technical advances that make it so attractive for next-generation development. Everything's here, from types and assignments to ownership, lifetimes, traits, and crates. Marshall even offers indispensable expert advice for unit testing, handling unsafe code, interoperating with legacy code bases, and using Rust's increasingly robust tools.

  • Contains short, easy-to-consume chapters

  • Clearly illustrates innovative features such as lifetimes, ownerships, and patterns

  • Practical, focused, complete, and up-to-date

  • Written for newcomers and professional developers alike

More than just a new language, Rust represents a philosophical shift in how you code. In Programming with Rust, you'll master both the techniques and the mindset.

Table of contents

  1. Cover Page
  2. About This eBook
  3. Halftitle Page
  4. Title Page
  5. Copyright Page
  6. Pearson’s Commitment to Diversity, Equity, and Inclusion
  7. Contents
  8. About the Author
  9. 1. Introduction to Rust
    1. Introduction
    2. Features
    3. Rust Terminology
    4. Tools
    5. Summary
  10. 2. Getting Started
    1. Preliminaries
    2. Rust and Windows
    3. Installing Rust
    4. Advanced Rustup
    5. “Hello, World”
    6. Compile and Run
    7. Cargo
    8. Library
    9. Comments
    10. Published Crates
    11. Main Function
    12. Command-Line Arguments
    13. Summary
  11. 3. Variables
    1. Terminology
    2. Variables
    3. Primitives
    4. Integer Types
    5. Overflow
    6. Notations
    7. Floating Point Types
    8. Floating Point Constants
    9. Infinity
    10. NaN
    11. Numeric Ranges
    12. Casting
    13. Boolean Types
    14. Char
    15. Pointers
    16. Operators
    17. Summary
  12. 4. Strings
    1. Str
    2. String
    3. Summary
  13. 5. Console
    1. Print
    2. Positional Arguments
    3. Variable Arguments
    4. Named Arguments
    5. Padding, Alignment, and Precision
    6. Base
    7. Developer Facing
    8. Write! Macro
    9. Display Trait
    10. Debug Trait
    11. Format! Macro
    12. Console Read and Write
    13. Summary
  14. 6. Control Flow
    1. The if Expression
    2. The while Expression
    3. The for Expression
    4. The loop Expression
    5. The loop Label
    6. The Iterator Trait
    7. Summary
  15. 7. Collections
    1. Arrays
    2. Vectors
    3. HashMap
    4. Summary
  16. 8. Ownership
    1. Stack and Heap Memory
    2. Shallow versus Deep Copy
    3. Car Analogy
    4. Move Semantics
    5. Borrow
    6. Copy Semantics
    7. Clone Trait
    8. Copy Trait
    9. Clone Trait
    10. Summary
  17. 9. Lifetimes
    1. Introduction to Lifetimes
    2. Function Headers and Lifetimes
    3. Lifetime Annotation
    4. Lifetime Elision
    5. Complex Lifetimes
    6. Sharing a Lifetime
    7. Static Lifetimes
    8. Structs and Lifetimes
    9. Methods and Lifetimes
    10. Subtyping Lifetimes
    11. Anonymous Lifetimes
    12. Generics and Lifetimes
    13. Summary
  18. 10. References
    1. Declaration
    2. Borrowing
    3. Dereferencing
    4. Comparing References
    5. Reference Notation
    6. Reference to Reference
    7. Mutability
    8. Limits to Multiple Borrowers
    9. Summary
  19. 11. Functions
    1. Function Definition
    2. Parameters
    3. Function Return
    4. Const Functions
    5. Nested Functions
    6. Function Pointers
    7. Function Aliases
    8. Summary
  20. 12. Error Handling
    1. Handling Error Handling
    2. The Result Enum
    3. The Option Enum
    4. Panics
    5. Unwrapping
    6. Match Pattern for Result and Option
    7. Map
    8. Rich Errors
    9. Custom Errors
    10. Summary
  21. 13. Structures
    1. Alternate Initialization
    2. Move Semantics
    3. Mutability
    4. Methods
    5. Self
    6. Associated Functions
    7. Impl Blocks
    8. Operator Overloading
    9. Tuple Struct
    10. Summary
  22. 14. Generics
    1. Generic Functions
    2. Bounds
    3. The where Clause
    4. Structs
    5. Associated Functions
    6. Enums
    7. Generic Traits
    8. Explicit Specialization
    9. Summary
  23. 15. Patterns
    1. Let Statement
    2. Wildcards
    3. Complex Patterns
    4. Ownership
    5. Irrefutable
    6. Ranges
    7. Multiple Patterns
    8. Control Flow
    9. Structs
    10. Functions
    11. Match Expressions
    12. Match Guards
    13. Summary
  24. 16. Closures
    1. “Hello, World”
    2. Closure Syntax
    3. Closed Over
    4. Closures as Function Arguments
    5. Closures as Function Return Values
    6. Implementation of Closures
    7. Matrix Example
    8. Summary
  25. 17. Traits
    1. Trait Definition
    2. Default Functions
    3. Marker Trait
    4. Associated Functions
    5. Associated Types
    6. Extension Methods
    7. Fully Qualified Syntax
    8. Supertraits
    9. Static Dispatch
    10. Dynamic Dispatch
    11. Enums and Traits
    12. Summary
  26. 18. Threads 1
    1. Synchronous Function Calls
    2. Threads
    3. The Thread Type
    4. Processor Time
    5. Builder
    6. Communicating Sequential Process
    7. Asynchronous Channel
    8. Synchronous Channel
    9. Rendezvous Channel
    10. The try Methods
    11. Store Example
    12. Summary
  27. 19. Threads 2
    1. Mutex
    2. Nonscoped Mutex
    3. Mutex Poisoning
    4. Reader-Writer Lock
    5. Condition Variables
    6. Atomic Operations
    7. Summary
  28. 20. Memory
    1. Stacks
    2. Static Values
    3. The Heap
    4. Interior Mutability
    5. RefCell
    6. OnceCell
    7. Summary
  29. 21. Macros
    1. Tokens
    2. Declarative Macros
    3. Procedural Macros
    4. Summary
  30. 22. Interoperability
    1. Foreign Function Interface
    2. Basic Example
    3. Libc Crate
    4. Structs
    5. Bindgen
    6. C Calling Rust Functions
    7. Cbindgen
    8. Summary
  31. 23. Modules
    1. Module Items
    2. Functions and Modules
    3. The crate, super, and self Keywords
    4. Legacy Model
    5. Summary
  32. Index
  33. Code Snippets

Product information

  • Title: Programming with Rust
  • Author(s): Donis Marshall
  • Release date: December 2023
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780137889754