Statistics
8
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-02-08

AuthorRic Messier

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.

Tags
No tags
ISBN: 1119712971
Publisher: Wrox / Wiley
Publish Year: 2021
Language: 英文
Pages: 416
File Format: PDF
File Size: 8.1 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
(This page has no text content)
BEGINNING RUST PROGRAMMING INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix CHAPTER 1 Game of Life: The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 CHAPTER 2 Extended Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 CHAPTER 3 Building a Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 CHAPTER 4 Hangman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 CHAPTER 5 In Concurrence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 CHAPTER 6 Clients and Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 CHAPTER 7 Client-Side Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 CHAPTER 8 Going Relational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 CHAPTER 9 No(SQL) Going . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 CHAPTER 10 Web Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 CHAPTER 11 Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 CHAPTER 12 Getting to the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 CHAPTER 13 Device Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 CHAPTER 14 Collecting Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 CHAPTER 15 Odds and Sods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
(This page has no text content)
BEGINNING Rust® Programming
(This page has no text content)
BEGINNING Rust® Programming Ric Messier
Beginning Rust® Programming Copyright © 2021 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-119-71297-8 ISBN: 978-1-119-71298-5 (ebk) ISBN: 978-1-119-71287-9 (ebk) Manufactured in the United States of America No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at booksupport.wiley .com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2020937958 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Rust is a registered trademark of Mozilla Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
ABOUT THE AUTHOR RIC MESSIER is an author, consultant, and educator who holds CCSP, GCIH, GSEC, CEH, and CISSP certifications and has published several books on information security and digital forensics. With dec- ades of experience in information technology and information security, Ric has held the varied roles of programmer, system administrator, network engineer, security engineering manager, VoIP engineer, consultant, and professor. He is currently a Principal Consultant with FireEye Mandiant.
(This page has no text content)
ABOUT THE TECHNICAL EDITOR JESSICA ROCCHIO has been in the information technology industry for over a decade and is currently an incident response consultant at Mandiant. Over the last few years, she has worked with various programming languages. She has spent most of her career in incident response, forensics, intelligence, insider threats, and vulnerability management. Jessica has worked on a wide range of incidents, including espionage, cybercrime, fraud, data theft, and insider threats.
(This page has no text content)
ACKNOWLEDGMENTS Without my tech editor, Jessica, and my project editor, Kim, I might not have made it through this book, so many thanks to them!
(This page has no text content)
CONTENTS 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
COnTEnTS xiv 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
COnTEnTS xv 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
COnTEnTS xvi 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
COnTEnTS xvii 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
COnTEnTS xviii 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