Statistics
11
Views
1
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-02-25

AuthorNouman Azam

Get "close to the machine" by programming with Rust! Discover how to effectively use this low-level language to create fast and efficient code. Set up Rust, compile your first program, and learn the language essentials: variables, functions, conditionals, and more. Walk through Rust’s unique ownership model and modular system, and then move on to more complex features, from flexibility and abstraction to web programming and text processing. Numerous code examples and exercises make this your go-to practical resource for Rust! In this book, you’ll learn about: a. Language Basics Take your first steps with Rust! After installation and setup in Visual Studio Code, walk through the language building blocks, from variables to functions to enums. Learn how to implement ownership, define types, test your code, and more. b. Intermediate Programming Expand your toolkit for Rust programming! Write flexible code with generics and traits, incorporate features of functional programming, manage memory, implement data structures, and handle structs. c. Advanced Topics Become a Rust master! Tackle advanced topics, including sized and unsized types, concurrency via threading, the powerful macro system, web programming, text processing, and file and directory handling. Highlights include: 1) Language basics 2) Control flow 3) Ownership 4) Structs and enums 5) Generics and traits 6) Modular structure 7) Memory management 8) Testing 9) Concurrency 10) Functional programming 11) Web programming 12) Text processing and file handling

Tags
No tags
Publisher: Rheinwerk Publishing Inc.
Publish Year: 2025
Language: 英文
File Format: PDF
File Size: 5.5 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)
Nouman Azam Rust The Practical Guide
Imprint This e-book is a publication many contributed to, specifically: Editor   Megan Fuerst Acquisitions Editor   Hareem Shafi Copyeditor   Yvette Chin Cover Design   Graham Geary     iStockphoto: 168329140/© ilbusca; Shutterstock: 1126625519/© Jackie Niam Production E-Book   Hannah Lane Typesetting E-Book   Satz-Pro, Germany We hope that you liked this e-book. Please share your feedback with us and read the Service Pages to find out how to contact us. The Library of Congress Cataloging-in-Publication Control Number for the printed edition is as follows: 2024061177
© 2025 by: Rheinwerk Publishing, Inc. 2 Heritage Drive, Suite 305 Quincy, MA 02171 USA info@rheinwerk- publishing.com +1.781.228.5070   Represented in the E.U. by: Rheinwerk Verlag GmbH Rheinwerkallee 4 53227 Bonn Germany service@rheinwerk- verlag.de +49 (0) 228 42150-0 ISBN 978-1-4932-2687-0 (print) ISBN 978-1-4932-2688-7 (e-book) ISBN 978-1-4932-2689-4 (print and e-book) 1st edition 2025
Notes on Usage This e-book is protected by copyright. By purchasing this e-book, you have agreed to accept and adhere to the copyrights. You are entitled to use this e-book for personal purposes. You may print and copy it, too, but also only for personal use. Sharing an electronic or printed copy with others, however, is not permitted, neither as a whole nor in parts. Of course, making them available on the internet or in a company network is illegal as well. For detailed and legally binding usage conditions, please refer to the section Legal Notes. This e-book copy contains a digital watermark, a signature that indicates which person may use this copy:  
Notes on the Screen Presentation You are reading this e-book in a file format (EPUB or Mobi) that makes the book content adaptable to the display options of your reading device and to your personal needs. That’s a great thing; but unfortunately not every device displays the content in the same way and the rendering of features such as pictures and tables or hyphenation can lead to difficulties. This e-book was optimized for the presentation on as many common reading devices as possible. If you want to zoom in on a figure (especially in iBooks on the iPad), tap the respective figure once. By tapping once again, you return to the previous screen. You can find more recommendations on the customization of the screen layout on the Service Pages.
Table of Contents Notes on Usage Table of Contents Preface
Part I   Basic Programming with Rust 1   Introduction 1.1   Installing Rust and Its Web-Based Environment 1.1.1   Installing Rust 1.1.2   Rust’s Web-Based Compiler 1.2   Running and Compiling Your First Program 1.3   Visual Studio Code Settings 1.4   Making the Most of This Book 1.5   Summary 2   Variables, Data Types, and Functions 2.1   Variables 2.1.1   Definition 2.1.2   Mutability of Variables 2.1.3   Scope of Variables
2.1.4   Shadowing 2.1.5   Constants 2.1.6   Statics 2.1.7   Unused Variables 2.2   Data Types 2.2.1   Primitive Data Types 2.2.2   Compound Data Types 2.2.3   Text-Related Types 2.3   Functions 2.4   Code Blocks 2.5   Practice Exercises 2.6   Solutions 2.7   Summary 3   Conditionals and Control Flow 3.1   Conditionals 3.1.1   If Else 3.1.2   If Else If Ladder 3.1.3   Match 3.2   Control Flow 3.2.1   Simple Loops 3.2.2   For and While Loops 3.3   Comments, Outputs, and Inputs
3.3.1   Comments 3.3.2   Formatting Outputs with Escape Sequences and Arguments 3.3.3   User Input 3.4   Practice Exercises 3.5   Solutions 3.6   Summary 4   Ownership 4.1   Ownership Basics 4.1.1   Values Must Have a Single Owner 4.1.2   When Owner Goes Out of Scope, the Value Is Cleaned Up 4.2   Ownership in Functions 4.2.1   Functions Taking Ownership 4.2.2   Function Returning Ownership 4.2.3   Function Taking and Returning Ownership 4.3   Borrowing Basics 4.3.1   Why Borrowing? 4.3.2   Borrowing Rules 4.3.3   Copying of References 4.4   Borrowing in Functions 4.5   Dereferencing 4.6   Mutable and Immutable Binding of
References 4.7   Practice Exercises 4.8   Solutions 4.9   Summary 5   Custom and Library- Provided Useful Types 5.1   Structs 5.1.1   Defining Structs 5.1.2   Instantiating Struct Instances 5.1.3   Ownership Considerations 5.1.4   Tuple Structs 5.1.5   Unit Structs 5.1.6   Adding Functionality to Structs 5.1.7   Associated Functions 5.2   Enums 5.2.1   Why Use Enums? 5.2.2   Defining Enums 5.2.3   Implementation Blocks for Enums 5.2.4   Adding Data to Enum Variants 5.3   Option 5.3.1   Why Use Option? 5.3.2   Defining the Option Enum 5.3.3   Matching on Option
5.3.4   Use of If Let with Option 5.4   Result 5.4.1   Why Use Result? 5.4.2   Defining the Result Enum 5.4.3   Matching on Result 5.4.4   The ? Operator 5.5   HashMaps 5.6   HashSets 5.7   Practice Exercises 5.8   Solutions 5.9   Summary 6   Organizing Your Code 6.1   Code Organization 6.2   Module Basics 6.2.1   Motivating Example for Modules 6.2.2   Creating Modules 6.2.3   Relative and Absolute Paths of Items 6.2.4   Privacy in Modules 6.2.5   The Use Declaration for Importing or Bringing Items into Scope 6.3   Visualizing and Organizing Modules 6.3.1   Cargo Modules for Visualizing Module Hierarchy
6.3.2   Organizing Code Using a Typical File System 6.4   Re-Exporting and Privacy 6.4.1   Re-Exporting with a Pub Use Expression 6.4.2   Privacy of Structs 6.5   Using External Dependencies 6.6   Publishing Your Crate 6.6.1   Creating an Account on crates.io 6.6.2   Adding Documentation before Publishing 6.6.3   Publishing Your Crate 6.7   Practice Exercises 6.8   Solutions 6.9   Summary 7   Testing Code 7.1   Unit Testing 7.1.1   A Typical Test Case 7.1.2   Writing a Test Function 7.1.3   Executing Tests 7.1.4   Testing with Result Enum 7.1.5   Testing Panics 7.2   Controlling Test Execution 7.3   Integration Tests 7.4   Benchmark Testing 7.5   Practice Exercises
7.6   Solutions 7.7   Summary
Part II   Intermediate Language Concepts 8   Flexibility and Abstraction with Generics and Traits 8.1   Generics 8.1.1   Basics of Generics 8.1.2   Generics in Implementation Blocks 8.1.3   Multiple Implementations for a Type: Generics versus Concrete 8.1.4   Duplicate Definitions in Implementation Blocks 8.1.5   Generics and Free Functions 8.1.6   Monomorphization 8.2   Traits 8.2.1   Motivating Example for Traits 8.2.2   Traits Basics 8.2.3   Default Implementations 8.2.4   Trait Bounds 8.2.5   Supertraits 8.2.6   Trait Objects 8.2.7   Derived Traits 8.2.8   Marker Traits
8.2.9   Associated Types in Traits 8.3   Choosing between Associated Types and Generic Types 8.4   Practice Exercises 8.5   Solutions 8.6   Summary 9   Functional Programming Aspects 9.1   Closures 9.1.1   Motivating Example for Closures 9.1.2   Basic Syntax 9.1.3   Passing Closures to Functions 9.1.4   Capturing Variables from the Environment 9.2   Function Pointers 9.3   Iterators 9.3.1   The Iterator Trait 9.3.2   IntoIterator 9.3.3   Iterating over Collections 9.4   Combinators 9.5   Iterating through Option 9.6   Practice Exercises 9.7   Solutions
9.8   Summary 10   Memory Management Features 10.1   Lifetimes 10.1.1   Concrete Lifetimes 10.1.2   Generic Lifetimes 10.1.3   Static Lifetimes 10.1.4   Lifetime Elision 10.1.5   Lifetimes and Structs 10.2   Smart Pointers 10.2.1   Box Smart Pointer 10.2.2   Rc Smart Pointer 10.2.3   RefCell Smart Pointer 10.3   Deref Coercion 10.4   Practice Exercises 10.5   Solutions 10.6   Summary 11   Implementing Typical Data Structures
11.1   Singly Linked List 11.1.1   Implementation by Modifying the List Enum 11.1.2   Resolving Issues with the Implementation 11.1.3   Refining the Next Field 11.1.4   Adding Elements 11.1.5   Removing Elements 11.1.6   Printing Singly Linked Lists 11.2   Doubly Linked List 11.2.1   Setting Up the Basic Data Structure 11.2.2   Adding Elements 11.2.3   Adding a New Constructor Function for Node 11.2.4   Removing Elements 11.2.5   Printing Doubly Linked Lists 11.3   Reference Cycles Creating Memory Leakage 11.4   Practice Exercises 11.5   Solutions 11.6   Summary 12   Useful Patterns for Handling Structs 12.1   Initializing Struct Instances 12.1.1   New Constructors
12.1.2   Default Constructors 12.2   Builder Pattern 12.2.1   Motivating Example for the Builder Pattern 12.2.2   Solving the Proliferation of Constructors 12.3   Simplifying Structs 12.4   Practice Exercises 12.5   Solutions 12.6   Summary
Part III   Advanced Language Concepts 13   Understanding Size in Rust 13.1   Sized and Unsized Types 13.1.1   Examples of Sized Types 13.1.2   Examples of Unsized Types 13.2   References to Unsized Types 13.3   Sized and Optionally Sized Traits 13.3.1   Opting Out of Sized Trait 13.3.2   Generic Bound of Sized Traits 13.3.3   Flexible Generic Function with Optionally Sized Trait 13.4   Unsized Coercion 13.4.1   Deref Coercion 13.4.2   Unsized Coercion 13.4.3   Unsized Coercion with Traits 13.5   Zero-Sized Types 13.5.1   Never Type 13.5.2   Unit Type 13.5.3   Unit Structs 13.5.4   PhantomData