Mastering Rust
- Length: 318 pages
- Edition: 1
- Language: English
- Publisher: CRC Press
- Publication Date: 2022-11-11
- ISBN-10: 1032319011
- ISBN-13: 9781032319018
- Sales Rank: #1221742 (See Top 100 Books)
Mastering Rust helps the reader master the powerful Rust programming language for creating stable and versatile applications and projects.
Rust is a dependable and robust programming language that was created with today’s needs in mind, which is something that several other scripting languages lack. Rust was developed to provide high functions comparable to those of C and C++, and with a focus on code integrity, which is, arguably, lacking in languages such as C. Rust is a dynamically typed language that emphasizes performance and reliability, particularly in parallelism and storage organization. Rust allows you to store data on the tower or the shedload, and it recognizes the importance of performance optimization. It permits even more effective memory usage as well as faster memory management than most other programming languages in its league.
Make no mistake about it – Rust is a programming language with a strong learning curve, and is considered complicated by even the most experienced of developers. The rewards for learning Rust are aplenty, but the learning process itself requires a good deal of determination and hard work.
Nonetheless, Rust aims to provide a secure, concurrent, and practical systems language in ways that other programming languages do not, and this is primarily why Rust is often the preferred choice for building complex and highly stable apps. Rust boasts of advantages over many other programming languages in terms of expressiveness, speed, sound design, and memory storage. Though the language is new and constantly changing with time, there is an excellent opportunity in this field for future employment.
That said, to learn the reliable language that is Rust, you need to have an equally reliable companion guide in your hands, and this is where Mastering Rust comes in.
With Mastering Rust, learning Rust programming language becomes a charm, and will undoubtedly help readers advance their careers.
The Mastering Computer Science series is edited by Sufyan bin Uzayr, a writer and educator with more than a decade of experience in the computing field.
Cover Half-Title Series Title Copyright Contents Mastering Computer Science Series Preface About the Editor CHAPTER 1 Getting Started with Rust WHAT EXACTLY IS RUST? Who Rust Is for Rust’s Increasing Popularity What Makes the Rust Programming Language Unique? Concurrent Programming Has Been Simplified Some Challenges to Overcome while Programming in Rust What Is the Purpose of Rust? Why Should We Use Rust? Features of Rust INSTALLING RUST Rust in Windows Installation Installing Rust on Linux or macOS Updating and Uninstalling Rust RUST FIRST PROGRAM Procedure for Creating, Compiling, and Running the Program REASONS WHY RUST IS THE WAY OF THE FUTURE Rust vs. Other Languages Advantages of Rust vs. C++ Advantages of Rust vs. Java Advantages of Rust vs. Python Advantages of Rust vs. Go What Makes Rust the Future? Rust Increased the Safety of Memory Rust’s Community Is Expanding Rust Is Quick and Adaptable Rust Has a Wide Range of Applications Rust Is Used by Several Large Companies CHAPTER 2 Common Programming Concepts VARIABLES IN RUST Variable Naming Rules Syntax IMMUTABLE MUTABLE Variables and Constants: What Are the Differences? DATA TYPES IN RUST Variable Declaration Scalar Types Integer Illustration Integer Range Integer Overflow Float Automatic-type Casting Number Separator Boolean Character Compound Types Tuple Type Array Type Accessing the Array Elements Invalid Array Element Access CONSTANT IN RUST Constant Naming Convention in Rust Constants vs. Variables Variable and Constant Shadowing STRING IN RUST String Literal String Object Syntax String Object – Common Methods Illustration: new() Illustration: to_string() Illustration: replace() Illustration: as_str() Illustration: push() Illustration: push_str() Illustration: len() Illustration: trim() Illustration: split_whitespace() Illustration: split() string Illustration: chars() Concatenation of the Strings with + Operator Illustration: String Concatenation Illustration: Type Casting Illustration: Format! Macro OPERATORS IN RUST Arithmetic Operators Relational Operators Logical Operators Bitwise Operators DECISION-MAKING IN RUST If Statement Syntax If else statement Syntax Flowchart Nested If Syntax Match Statement Syntax Using an “if” statement within a “let” statement Syntax LOOPS IN RUST Loop Syntax Exit from Loops While Loop Syntax Flowchart While Loop Disadvantages FOR LOOP Syntax Distinctions between the While Loop and For Loop FUNCTIONS IN RUST Function Defining Syntax Function Invoking Syntax Illustration Returning Value from a Function Syntax Function with the Parameters Pass by Value Pass by Reference Passing String to a Function COMMENTS IN RUST TUPLE IN RUST Destructing ARRAY IN RUST Array Characteristics Array Declaration and Initialization Syntax Illustration: Simple Array Illustration: Array without Data Type Illustration: Default Values Illustration: Array with for Loop Illustration: Using the iter() Function Illustration: Mutable Array Passing Arrays as Parameters to the Functions Illustration: Pass by Value Illustration: Pass by Reference The Array Declaration and Constants CHAPTER 3 Understanding Ownership WHAT EXACTLY IS OWNERSHIP? The Stack and the Heap Important Ownership Concepts Rules of Ownership Variable Scope String Type Memory and Allocation Ways of Variables and Data Interact: Move Variables and Data Interactions: Clone Stack-Only Data: Copy Ownership and Functions Return Values and Scope REFERENCES AND BORROWING IN RUST Why Borrowing? Mutable Reference Restrictions of the Mutable References Dangling References The Referencing Guidelines SLICES IN RUST String Slices Literals Are String Slices String Slices as Parameters Other Slices CHAPTER 4 Using Structs for Related Data WHAT IS THE DEFINITION OF A STRUCTURE? When the Variables and Fields Have the Same Name, Use the Field init Shorthand Using Struct Update Syntax to Create Instances from Other Instances The Tuple Structs without Named Fields to Create Different Types Structs that Look Like Units but Don’t Have Any Fields Ownership of Struct Data UPDATE SYNTAX An Example of a Structs Program Refactoring with the Tuples Using Structs for Refactoring: Adding Additional Meaning Using Derived Traits to Add Useful Functionality METHOD SYNTAX Defining the Methods Methods with More Parameters Associated Functions Multiple impl Blocks CHAPTER 5 Enums and Pattern Matching DEFINING AN ENUM Enum Values The Advantages of the Option Enum over Null Values THE MATCH CONTROL FLOW OPERATOR Patterns that Bind to Values Matching with the Option<T> Matches Are Exhaustive Catch-all Patterns and the _ Placeholder CONCISE CONTROL FLOW WITH IF LET CHAPTER 6 Packages, Crates, and Modules PACKAGES AND CRATES DEFINING MODULES TO THE CONTROL SCOPE AND PRIVACY PATHS FOR REFERRING TO AN ITEM IN THE MODULE TREE Exposing Paths with pub Keyword Starting Relative Paths with super Making Structs and Enums Public BRINGING PATHS INTO THE SCOPE WITH THE USE KEYWORD Creating the Idiomatic use Paths Providing New Names with the as Keyword Re-exporting Names with pub use SEPARATING MODULES INTO DIFFERENT FILES CHAPTER 7 Error Handling ERROR HANDLING Unrecoverable Errors with panic! Unwinding Stack or Aborting in Response to a Panic Using panic! Backtrace RECOVERABLE ERRORS WITH THE RESULT Shortcuts for the Panic on Error: unwrap and expect Propagating Errors Shortcut for Propagating Errors: the ? Operator The ? Operator Can Be Used in Functions that Return Result TO PANIC! OR NOT TO PANIC! Examples, Prototype Code, and Tests Cases in Which We Have More Information than the Compiler Guidelines for the Error Handling Creating the Custom Types for Validation CHAPTER 8 Generic Types, Traits, and Lifetimes GENERIC DATA TYPES In Function Definitions In the Struct Definitions In Method Definitions Performance of Code Using Generics Traits: Defining Shared Behavior Defining a Trait Implementing a Trait on a Type VALIDATING REFERENCES WITH LIFETIMES Preventing Dangling References with Lifetimes Borrow Checker Generic Lifetimes in the Functions CHAPTER 9 I/O Project: Building a Command Line Program ACCEPTING THE COMMAND LINE ARGUMENTS Saving the Argument Values in the Variables READING A FILE Refactoring to Improve Modularity and Error Handling Separation of Concerns for Binary Projects Extracting the Argument Parser Grouping the Configuration Values Creating a Constructor for the Config Fixing the Error Handling Improving the Error Message DEVELOPING THE LIBRARY’S FUNCTIONALITY WITH THE TEST-DRIVEN DEVELOPMENT WORKING WITH THE ENVIRONMENT VARIABLES Writing Failing Test for the Case-Insensitive search Function Implementing search_case_insensitive Function WRITING ERROR MESSAGES TO THE STANDARD ERROR INSTEAD OF STANDARD OUTPUT Checking Where Errors Are Written Printing Errors to the Standard Error CHAPTER 10 Cargo and crates.io CUSTOMIZING BUILDS WITH THE RELEASE PROFILES PUBLISHING A CRATE TO CRATES.IO Making Useful Documentation Comments Commonly Used Sections Documentation Comments as Tests Commenting Contained Items Exporting a Convenient Public API with the pub use Setting Up crates.io Account CARGO WORKSPACES Creating a Workspace Creating the Second Package in the Workspace INSTALLING BINARIES FROM CRATES.IO WITH CARGO INSTALL EXTENDING CARGO WITH THE CUSTOM COMMANDS CHAPTER 11 Concurrency and State FEARLESS CONCURRENCY USING THREADS TO RUN CODE SIMULTANEOUSLY Creating New Thread with spawn Waiting for All the Threads to Finish Using JoinHandle USING MESSAGE PASSING TO THE TRANSFER DATA BETWEEN THREADS The Channels and Ownership Transference Sending Multiple Values and Seeing the Receiver Waiting Creating Multiple Producers by Cloning the Transmitter SHARED-STATE CONCURRENCY Using Mutexes to Allow Data Access from Only One Thread at a Time API of Mutex<T> Sharing Mutex<T> Between Multiple Threads EXTENSIBLE CONCURRENCY WITH SYNC AND SEND TRAITS Allowing Transference of the Ownership between Threads with Send Allowing Access from the Multiple Threads with Sync Implementing the Send and Sync Manually Is Unsafe CHAPTER 12 Object-oriented Programming in Rust IMPLEMENTING AN OBJECT-ORIENTED DESIGN PATTERN Defining Post and Creating New Instance in the Draft State Storing the Text of the Post Content Ensuring Content of a Draft Post Is Empty Requesting a Review Changes the State of the Post Trade-offs of the State Pattern MACROS Difference between Macros and Functions Declarative Macros with macro_rules! for General Metaprogramming Procedural Macros for Generating Code from the Attributes How to Write a Custom derive Macro Attribute-like Macros Function-like Macros APPENDIX A: KEYWORDS APPENDIX B: OPERATORS AND SYMBOLS APPENDIX C: DERIVABLE TRAITS APPRAISAL BIBLIOGRAPHY INDEX
Donate to keep this site alive
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.