Beginning Rust Programming

45.90

ISBN : 9781119712978.
Catégorie : .
Editeur

Auteur(s)

Edition

Nombre de pages

Collection


Quickly learn the ropes with the Rust programming language using this practical, step-by-step guide

In Beginning Rust Programming, accomplished programmer and author Ric Messier delivers a highly practical, real-world guide to coding with Rust. Avoiding dry, theoretical content and “Hello, world”-type tutorials of questionable utility, the book dives immediately into functional Rust programming that takes advantage of the language’s blazing speed and memory efficiency.

Designed from the ground up to give you a running start to using the multiparadigm system programming language, this book will teach you to:

  • Solve real-world computer science problems of practical importance
  • Use Rust’s rich type system and ownership model to guarantee memory-safety and thread-safety
  • Integrate Rust with other programming languages and use it for embedded devices

Perfect for programmers with some experience in other languages, like C or C++, Beginning Rust Programming is also a great pick for students new to programming and seeking a user-friendly and robust language with which to start their coding career.

Introduction xix

Chapter 1: Game of Life: The Basics 1

Game of Life: The Program 2

Starting with Cargo 4

Putting the Pieces Together 5

Bringing In External Functionality 5

Namespaces 6

Generating the Game Grid 7

Dissecting Main 8

Defining Functions 8

Defining Variables 9

Datatypes 11

Arrays 12

Control Structures 14

Looking at More Function Functions 16

Returning Values 16

Passing Parameters 18

Scope 21

Compiling Programs 22

Summary 24

Exercises 25

Additional Resources 25

Chapter 2: Extended Life 27

Understanding Ownership 28

Extending Life 30

Adding Modules 32

Working with Command-Line Arguments 34

Option Types 36

Reading from Files 39

Extracting Values 41

Populating from the Vector 42

Outputting to the Terminal 43

Using Colors 44

Printing Generations 44

Summary 46

Exercises 48

Additional Resources 48

Chapter 3: Building A Library 49

References 50

First Pass 53

Traits and Implementations 56

Self-Identification 60

The Rest 60

Second Pass 62

The Driver 65

Summary 67

Exercises 69

Additional Resources 69

Chapter 4: Hangman 71

Our Data 74

The Traits 77

Implementations 79

Using the Option Enum 82

Finishing Up the Implementation 83

Reading Files and Selecting Words 84

Handling Errors Concisely 85

Generics and Bounds 87

A Vector of Lines 88

The Rest of the Story 90

Initialization 91

Playing the Game 92

Summary 94

Exercises 95

Additional Resources 95

Chapter 5: In Concurrence 97

The Dining Philosophers 98

Mutexes and Semaphores 101

Interprocess Communications 103

The Main Event 106

Unix Sockets 107

File and Directory Handling 109

Closures 112

Threading in the Main 114

Creating Streams 115

Cryptographic Hashing 116

Creating Threads 117

Summary 118

Exercises 119

Additional Resources 119

Chapter 6: Clients and Servers 121

Planning 123

Network Programming 125

Programming Sockets 128

Rust TCP Server 131

Handling Requests 134

Operating System Calls 137

Summary 139

Exercises 140

Additional Resources 140

Chapter 7: Client-Side Applications 141

Encryption 142

Encryption Algorithms 144

Going Hybrid 145

Encryption Algorithms 147

Transport Layer Security (TLS) 147

TLS Server 151

Remote Access Client 154

Creating the Connection 156

Validating Input 157

Regular Expressions 157

The Final Function 159

Summary 163

Exercises 164

Additional Resources 164

Chapter 8: Going Relational 165

Application Architectures 166

n-Tier Applications 167

Microservices 169

Model-View-Controller 171

Databases 172

Structured Query Language 172

Server or Embedded 175

Accessing Databases 176

Writing a Database Program 177

Main and Modules 178

Database Functions 183

Adding Records 184

Listing Records 186

Summary 189

Exercises 190

Additional Resources 190

Chapter 9: NO(SQL) Going 191

Assertions 192

Design by Contract 195

NoSQL 198

Working with MongoDB 202

Inserting Data 202

Reading in Data from a File 206

Populating the Database 207

Retrieving Values 209

Summary 213

Exercises 214

Additional Resources 214

Chapter 10: Web Communications 215

Style Guides 216

Hypertext Transfer Protocol 219

Programmatic Communication 222

Web Communication Over TLS 227

Client Communication 229

Jumping Ahead 232

Jumping Back 237

Summary 238

Exercises 239

Additional Resources 240

Chapter 11: Web Server 241

Offensive vs. Defensive Programming 242

Web Application Communications 245

Web Application Parameters 245

Asynchronous JavaScript and XML 248

Representational State Transfer 249

APIs in Node.js and Python 250

API Server in Rust 252

Rust Rocket 255

Summary 262

Exercises 262

Additional Resources 263

Chapter 12: Getting to the System 265

Extending Functionality 266

Windows Registry 272

Programmatic Access to the Registry 275

Using Rust to Access the Registry 277

System Information with Rust 282

Persistence (for Fun) 287

Summary 289

Exercises 290

Additional Resources 290

Chapter 13: Device Programming 291

Logging 292

Using syslog 292

Using Windows Event Logs 299

Working with Raspberry Pi 305

Lighting Lights 310

Reading GPIO 315

Summary 318

Exercises 319

Additional Resources 319

Chapter 14: Collecting Stuff 321

Arrays and Vectors 322

Linked Lists 329

Stacks 333

Queues 336

Sorting 337

Search Trees 340

Summary 345

Exercises 346

Additional Resources 346

Chapter 15: Odds and Sods 347

Unit Testing 348

Testing Types 350

Test Plans 351

Unit Tests 353

Recursion 360

Machine Learning 364

Chatbots 366

Neural Networks 369

Summary 371

Exercises 373

Additional Resources 373

Index 375