Skip to main content

English

Published by Addison-Wesley Professional (February 1, 2024) © 2024

Donis Marshall
    VitalSource eTextbook ( Lifetime access )
    €32,99

    Including VAT (as applicable)

    ISBN-13: 9780137889396

    Programming with Rust ,1st edition

    Language: English

    Product Information

    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.

    Chapter 1: Introduction to Rust 1

    Introduction 1

    Features 4

    Rust Terminology 6

    Tools 7

    Summary 8

     

    Chapter 2: Getting Started 9

    Preliminaries 9

    Rust and Windows 10

    Installing Rust 10

    Advanced Rustup 11

    “Hello, World” 11

    Compile and Run 12

    Cargo 13

    Library 15

    Comments 17

    Published Crates 20

    Main Function 21

    Command-Line Arguments 22

    Summary 23

     

    Chapter 3: Variables 25

    Terminology 25

    Variables 26

    Primitives 26

    Integer Types 27

    Overflow 28

    Notations 29

    Floating Point Types 30

    Floating Point Constants 30

    Infinity 31

    NaN 31

    Numeric Ranges 32

    Casting 33

    Boolean Types 34

    Char 34

    Pointers 35

    Operators 37

    Summary 40

     

    Chapter 4: Strings 41

    Str 41

    String 42

    Length 43

    Extending a String 44

    Capacity 45

    Accessing a String Value 46

    String Characters 48

    Deref Coercion 48

    Formatted String 49

    Helpful Functions 49

    Summary 52

     

    Chapter 5: Console 53

    Print 53

    Positional Arguments 54

    Variable Arguments 55

    Named Arguments 55

    Padding, Alignment, and Precision 56

    Base 58

    Developer Facing 59

    Write! Macro 60

    Display Trait 60

    Debug Trait 62

    Format! Macro 63

    Console Read and Write 63

    Summary 64

     

    Chapter 6: Control Flow 65

    The if Expression 65

    The while Expression 68

    The for Expression 70

    The loop Expression 73

    The Iterator Trait 76

    Summary 78

     

    Chapter 7: Collections 79

    Arrays 79

    Vectors 86

    HashMap 91

    Summary 95

     

    Chapter 8: Ownership 97

    Stack and Heap Memory 98

    Shallow versus Deep Copy 98

    Car Analogy 99

    Move Semantics 99

    Borrow 101

    Copy Semantics 101

    Clone Trait 102

    Copy Trait 103

    Clone Trait 104

    Summary 105

     

    Chapter 9: Lifetimes 107

    Introduction to Lifetimes 108

    Function Headers and Lifetimes 109

    Lifetime Annotation 111

    Lifetime Elision 112

    Complex Lifetimes 113

    Sharing a Lifetime 114

    Static Lifetimes 115

    Structs and Lifetimes 116

    Methods and Lifetimes 116

    Subtyping Lifetimes 118

    Anonymous Lifetimes 120

    Generics and Lifetimes 121

    Summary 121

     

    Chapter 10: References 123

    Declaration 124

    Borrowing 124

    Dereferencing 125

    Comparing References 126

    Reference Notation 127

    Reference to Reference 128

    Mutability 129

    Limits to Multiple Borrowers 130

    Summary 131

     

    Chapter 11: Functions 133

    Function Definition 133

    Parameters 134

    Function Return 136

    Const Functions 138

    Nested Functions 139

    Function Pointers 140

    Function Aliases 142

    Summary 143

     

    Chapter 12: Error Handling 145

    Handling Error Handling 145

    The Result Enum 146

    The Option Enum 147

    Panics 148

    Unwrapping 154

    Match Pattern for Result and Option 156

    Map 158

    Rich Errors 160

    Custom Errors 161

    Summary 163

     

    Chapter 13: Structures 165

    Alternate Initialization 167

    Move Semantics 169

    Mutability 170

    Methods 170

    Self 172

    Associated Functions 173

    Impl Blocks 174

    Operator Overloading 175

    Tuple Struct 179

    Summary 180

     

    Chapter 14: Generics 181

    Generic Functions 182

    Bounds 186

    The where Clause 188

    Structs 190

    Associated Functions 194

    Enums 195

    Generic Traits 197

    Explicit Specialization 200

    Summary 205

     

    Chapter 15: Patterns 207

    Let Statement 207

    Wildcards 208

    Complex Patterns 209

    Ownership 210

    Irrefutable 212

    Ranges 213

    Multiple Patterns 214

    Control Flow 215

    Structs 216

    Functions 219

    Match Expressions 220

    Match Guards 224

    Summary 227

     

    Chapter 16: Closures 229

    “Hello, World” 229

    Closure Syntax 230

    Closed Over 231

    Closures as Function Arguments 233

    Closures as Function Return Values 234

    Implementation of Closures 235

    Matrix Example 242

    Summary 244

     

    Chapter 17: Traits 245

    Trait Definition 245

    Default Functions 248

    Marker Trait 249

    Associated Functions 249

    Associated Types 251

    Extension Methods 253

    Fully Qualified Syntax 254

    Supertraits 257

    Static Dispatch 260

    Dynamic Dispatch 262

    Enums and Traits 263

    Summary 265

     

    Chapter 18: Threads 1 267

    Synchronous Function Calls 268

    Threads 269

    The Thread Type 273

    Processor Time 274

    Builder 275

    Communicating Sequential Process 276

    Asynchronous Channel 277

    Synchronous Channel 279

    Rendezvous Channel 280

    The try Methods 281

    Store Example 286

    Summary 290

     

    Chapter 19: Threads 2 291

    Mutex 291

    Nonscoped Mutex 294

    Mutex Poisoning 296

    Reader-Writer Lock 297

    Condition Variables 299

    Atomic Operations 301

    Summary 305

     

    Chapter 20: Memory 307

    Stacks 307

    Static Values 309

    The Heap 310

    Interior Mutability 312

    RefCell 316

    OnceCell 318

    Summary 319

     

    Chapter 21: Macros 321

    Tokens 322

    Declarative Macros 323

    Repetition 325

    Multiple Macro Matchers 327

    Procedural Macros 328

    Derive Macros 329

    Attribute Macros 332

    Function-Like Macros 334

    Summary 335

     

    Chapter 22: Interoperability 337

    Foreign Function Interface 337

    Basic Example 339

    Libc Crate 341

    Structs 342

    Bindgen 346

    C Calling Rust Functions 347

    Cbindgen 348

    Summary 351

     

    Chapter 23: Modules 353

    Module Items 354

    Module Files 358

    The path Attribute 360

    Functions and Modules 361

    The crate, super, and self Keywords 362

    Legacy Model 363

    Summary 365

     

    Index 367

    Top