Rust Crash Course: Build High-Performance, Efficient and Productive Software with the Power of Next-Generation Programming Skills (English Edition)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Grasp the fundamentals of programming in Rust and put your knowledge to use

KEY FEATURES

● Includes the basics of Rust, its advanced features, and how to get started with coding in Rust.

● Numerous projects that improve coding, concept fluency, and real-world experience.

● Every part of Rust is introduced and explained in detail, along with how to use it.

DESCRIPTION

Rust is a sophisticated systems programming language for speed, memory safety, and parallelism. This book gives you a fast introduction to Rust so that you may get started with low-level system programming and developing web applications, network services, and embedded programmes.

The book begins with instructions on setting up the Rust environment, developing a "hello world" programme, and getting started with cargo, the Rust package manager and the build tool. The book is a crash course, although it covers fundamental programming principles like variables and mutability, data types, comments, and control flow. Very precisely, topics such as ownership, borrowing, structs, enums, and other collections are covered. Error handling, memory management, and concurrency are well-demonstrated using practical projects. The book explains how to construct automated tests, write multithreaded applications, and utilise common data structures without difficulty. The book concludes with several hands-on projects, including creating a CLI application, a web app, a binary image classifier, and an embedded programme.

After reading this book, you will have a thorough understanding of the principles of Rust programming and be able to produce idiomatic Rust code for your projects, as well as improved tests and documentation.

WHAT YOU WILL LEARN

● Learn Rust's Cargo, fundamental concepts, collections, generic data types, iterators, and closures.

● Learn to write and experience the working of memory-safe programs.

● Implement and practice various data structures and algorithms.

● Get familiar with Rust module systems such as packages, crates, modules, and paths.

● Work with error handling, code testing, and working of concurrency capability.

WHO THIS BOOK IS FOR

This book is intended for software developers and system programmers interested in Rust as a C/C++ alternative. This book is also available to students interested in learning systems programming using Rust. The book assumes you have prior knowledge of basic programming concepts or any other programming language.

Author(s): Abhishek Kumar
Publisher: BPB Publications
Year: 2022

Language: English
Pages: 328

Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
Acknowledgements
Preface
Errata
Table of Contents
1. Setup and Installation of Rust
Structure
Objectives
Installing Rust
Updating and uninstalling
Writing a Hello World program
Working with cargo
Creating a Hello World project with cargo
Understanding Cargo.toml file
Building and running with cargo
Conclusion
Questions
Points to remember
2. General Programming Concepts
Structure
Objectives
Variables
Declaring a variable
Mutability
Data types
Scalar data types
Integer
Floating-point
Boolean
Characters
Compound data types
Tuples
Arrays
Adding comments
Functions
Control flow
if expression
if … else
if … else if
Loops
loop
while loop
for loop
Conclusion
Problems
Points to remember
3. Ownership and Memory Management
Introduction
Structure
Objectives
Ownership principal in Rust
Memory allocation on stack and heap
String data type
Memory allocation for String type
Move
Clone
Copy
References and borrowing
Slice
Conclusion
Questions
Points to remember
4. Structs, Enums, and Collections
Introduction
Structure
Objectives
Structs
Defining structs
Instantiating and using structs
Field init shorthand
Struct update syntax
Tuple structs
Methods
Defining methods
Using methods
Associated functions
Enums
Option enum
The match operator
Collections
Vector
Creating a vector
Updating a vector
Accessing elements of a vector
String
Creating a String
Updating a String
Accessing bytes and characters of a String
Hash map
Creating a hash map
Accessing values in a hash map
Removing a value from a hash map
Conclusion
Questions
Points to remember
5. Organizing Your Code
Introduction
Structure
Objectives
Rust’s module system
Packages
Crates
Creating a binary crate
Creating a library crate
Modules
Paths and use
Conclusion
Questions
Points to remember
6. Error Handling
Introduction
Structure
Objectives
Rust’s error handling
Recoverable errors and Result
Common Result methods
Unrecoverable errors and panic!
Using Backtrace
Changing the default panic behavior
Conclusion
Questions
Points to remember
7. Generics and Traits
Introduction
Structure
Objectives
Generic data types in Rust
Structs using generic types
Functions using generic types
Enums using generic types
Methods using generic types
Traits
Defining a trait
Implementing a trait
Default implementation of Trait’s methods
Implementing multiple traits
Traits as function parameters
impl trait syntax
Trait bound syntax
Multiple parameters of same trait
Parameters implementing multiple traits
Conclusion
Questions
Points to remember
8. Testing Your Code
Introduction
Structure
Objectives
Writing software tests
Unit tests
Writing a test function
Assert helper macros
Running test functions
Running specific tests
Ignoring execution of tests
Integration tests
Creating integration tests
Running integration tests
Conclusion
Questions
Points to remember
9. Iterators and Closures
Introduction
Structure
Objectives
Closures
Defining and calling a closure
Type inference
Closure as member of a struct
Capturing environment
Iterators
The Iterator trait
Defining a counter with Iterator trait
iter(), into_iter(), and iter_mut()
Iterators versus loops
Conclusion
Questions
Points to remember
10. Smart Pointers
Introduction
Structure
Objectives
Pointers in Rust
Smart pointers in Rust
Box
Defining recursive types with Box
Rc
RefCell
Conclusion
Questions
Points to remember
11. Concurrency
Introduction
Structure
Objectives
Threads
Threading models
One-to-one model
Many-to-one model
Many-to-many model
Creating a thread - spawn
Waiting for a thread - join
Message-passing concurrency
Shared-state concurrency
Mutex
Arc
Sync and Send traits
Conclusion
Questions
Points to remember
12. Object-Oriented Features
Introduction
Structure
Objectives
Characteristics of object-oriented programming
Inheritance
Encapsulation
Abstraction
Polymorphism
Using generics and trait bounds - static dispatch
Using trait objects - dynamic dispatch
Implementing OOP pattern
Conclusion
Questions
Points to remember
13. Implementing Data Structures – Linked List, Trees, Hash Table, and Graph
Introduction
Structure
Objectives
Linked list data structure
Trees, binary trees, and binary search trees
Hash tables
Graph and its representations
Conclusion
Questions
Points to remember
14. Rust for Windows Developers
Introduction
Structure
Objectives
Windows development with Rust
Developing a calculator application on Windows
Creating and setting up the project
Designing the UI
Implementing the calculator application
Conclusion
Questions
Points to remember
15. Rust for Android
Introduction
Structure
Objectives
Rust in Android platform
Systems programming on Android
Legacy C/C++ code
Integration to Android Open-Source Project
Rust modules in Android
Rust module definition
Common module properties
name
stem
srcs
crate_name
lints
edition
flags
ld_flags
features
cfgs
strip
host_supported
Android Rust module types
rust_binary
rust_binary_host
rust_library
rust_ffi
rust_proc_macro
rust_test
rust_fuzz
rust_bindgen
Developing a Hello Rust module
Conclusion
Questions
Points to remember
16. Project 1 – Building a CLI Application
Introduction
Structure
Objectives
To-do list
Implementing To-do list
Creating the project
Capturing command-line arguments
Defining the To-do structure
Implementing methods of Todo struct
Running the application
Conclusion
Questions
Points to remember
17. Project 2 – Running Rust from a Web Browser
Introduction
Structure
Objectives
WebAssembly
Setting up our environment
Installing Rust
wasm-pack
cargo-generate
npm
Creating a hello-wasm project
Creating wasm-login project
Database
Docker
Conclusion
Questions
Points to remember
18. Project 3 – Embedded Rust Hello World
Introduction
Structure
Objectives
Non-standard Rust program
Non-standard Rust program
Program overview
Running the program
Debugging the program
Conclusion
Questions
Points to remember
19. Project 4 – Building a Binary Image Classifier using Neural Networks
Introduction
Structure
Objectives
What are neural networks?
How do neural networks work?
Implementing a binary image classifier using neural networks
Creating a Rust project
Adding project dependencies
Training and test data
Defining our model
Conclusion
Questions
Points to remember
Index