1. Introduction to Rust
Introduction
Structure
Objectives
Installing Rust
Getting started with Cargo
Bin versus Lib
Bindings and mutability
Guessing game
Ownership
How Rust manages memory
Owning and borrowing values
Copy and clone
Borrowing rules
Rules
Pointer types
Control flow
Logic operators
Conditional operators
If/Else Statements
Match statements
Loops
While loops
For loops
Loop Statements
Functions
Declaring functions
Modules and publicity
Super versus self
Testing and benchmarking
Structs and Enums
Structures
Traditional C Struct
Tuple Struct
Empty Struct
Enumerations
Conclusion
Key facts
Exercises
Answers
2. OOP in Structs and Enums
Introduction
Structure
Objectives
From classes to structures
Implementations
Traits
Deriving traits
Type aliasing
From templates to generics
Generic structs
Generic traits
Conclusion
Key facts
Exercises
Answers
3. Error Handling
Introduction
Structure
Objectives
Error Handling in C, C++, and Rust
The Option<T> type
The Result<T, E> type
Converting a Result to an Option
Creating a custom error type
How could we improve?
Conclusion
Key facts
Exercises
Answers
4. Project – Building a CLI App
Introduction
Structure
Objectives
Creating the base of the application
A crash course in Async
Creating the web server
Creating the client
Testing out the client
How can we improve
How to publish?
Conclusion
Key facts
Exercises
Answers
5. Concurrency in Rust
Introduction
Structure
Objectives
Smart pointers
Heap-allocated values using box
Reference counting using Rc & Arc
Interior mutability using Cell and RefCell
The importance of concurrency
Implementing concurrency using threads
Passing values using channels
Using locking types to Write/Read bindings
Single-threaded access using Mutex
Multi-threaded reader using RwLock
Conclusion
Key facts
Exercises
Answers
6. Networking in Rust
Introduction
Structure
Objectives
The protocol stack
Physical layer
Data link layer
Network layer
Transport layer
Application Layer
Exploring the Net module
Creating a synchronous IO model
Testing using Redis
Creating an asynchronous IO model
The Future trait
From Mio to Tokio
How can we improve?
Conclusion
Key facts
Exercises
Answers
7. Project – GTK App
Introduction
Structure
Objectives
Setting up our GTK application
Row data for our grocery list
Storing rows into a model
Assembling the final application
Building the user interface
Testing our GTK application
Conclusion
Key facts
Exercises
Answers
8. Unsafe Rust and FFI
Introduction
Structure
Objectives
Using the unsafe keyword
Unsafe functions
Unsafe traits
Using C in Rust
Using Rust in C
Conclusion
Key facts
Exercises
Answers
9. Metaprogramming
Introduction
Structure
Objectives
When to create macros?
Declarative macros
Creating a declarative macro
Repetition
Procedural macros
Derive macros
Attribute macros
Useful attributes
Function-like macros
Conclusion
Key facts
Exercises
Answers
10. Project – StdLib for Mufi
Introduction
Structure
Objectives
Getting started with Mufi-Lang
Declaring variables in Mufi
Control flow in Mufi
Loops in Mufi
Functions in Mufi
Classes in Mufi
Inheritance in Mufi
Creating native functions in C
Creating native functions in Rust
Benchmarking C versus Rust native functions
Conclusion
Key facts
Exercises
Answers
11. Project – App in Tauri
Introduction
Structure
Objectives
Getting started with Tauri
Systems dependencies
Hello World in Tauri
Getting familiar with Svelte
Overview of the application
Creating the application
More with Tauri
Error handling
Nesting each loops
Challenges with Tauri development
Conclusion
Key facts
Exercises
Answers
Rust is one of the most loved programming languages among developers. It is rapidly being adopted as the industry moves towards memory-safety systems programming languages. If you want to switch from C/C++ to Rust, this book is for you.
“Rust for C++ Programmers” is the perfect guide to help you master the Rust programming language. Beginning with its evolution and comparison to C/C++, the book will help you learn how to install and use the powerful Cargo package manager. The book then covers key topics such as bindings and mutability, ownership, conditionals, loops, functions, structs and enums, and more. The book also explains how to handle errors in Rust. Furthermore, the book explores advanced topics such as smart pointers, concurrency, and even building a desktop application using GTK.
By the end of the book, you will be able to build powerful and resilient apps with Rust.
This book is for programmers who are familiar with C/C++ and are looking to add Rust to their toolbelt.