Practical Rust Web Projects: Building Cloud and Web-Based ApplicationS

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"

Go beyond the basics and build complete applications using the Rust programming language, updated for Rust 2021 edition. The applications you'll build over the course of this book include a high-performance web client, an embedded computer (for a robot, for example), a game, a serverless web app, and an application that incorporates AI and machine learning. Each chapter is organized in the following format: what the kind of should application look like; requirements and user stories of our example program; an introduction to the Rust libraries used; the actual implementation of the example program, including common pitfalls and their solutions; and a brief comparison of libraries for building each application, if there is no clear preference. Practical Rust Projects, Second Edition will open your eyes to how Rust can be put to practical, real-world use. After reading this book, you will be able to use Rust to build a variety of your own projects. What You Will Learn Explore practical Rust programming language-based projects, examples and case studies Create a GUI Build a high performance web Front-end using WebAssembly Develop REST APIs using Rust Go serverless to develop a cloud application using the Amazon AWS Rust SDK Create a game using Rust, along with AI and machine learning apps Who This Book Is For Those with basic Rust knowledge who want to learn more about how to apply Rust in real-world scenarios.

Author(s): Shing Lyu, Andrew Rzeznik
Edition: 2
Publisher: Apress
Year: 2023

Language: English
Pages: 397

Table of Contents
About the Authors
About the Technical Reviewer
Introduction
Chapter 2: Building a Command-line Program
2.1 What Are You Building?
2.2 Creating a Binary Project
2.3 Reading Command-line Arguments with std::env::args
2.4 Handling Complex Arguments with Clap
2.5 Adding Binary Flags
2.6 Printing to STDERR
2.7 Printing with Color
2.8 Reading the Cat Picture from a File
2.9 Handling Errors
2.10 Piping to Other Commands
Piping to STDOUT Without Color
Accepting STDIN
2.11 Integration Testing
2.12 Publishing and Distributing the Program
Install from Source
Publish to crates.io
Building Binaries for Distribution
2.13 Conclusion
Chapter 3: Creating Graphical User Interfaces (GUIs)
3.1 What Are You Building?
3.2 Building a Text-based User Interface
3.3 Showing a Dialog Box
3.4 Handling Simple Keyboard Inputs
3.5 Adding a Dialog
3.6 Multi-step Dialogs
3.7 Reading User Input
3.8 Moving to Graphical User Interfaces (GUIs)
3.9 Creating a Window
3.10 Displaying an Image
3.11 Using Glade to Design the UI
3.12 Accepting Inputs and Button Clicks
3.13 Reading a gtk::Switch
3.14 Alternatives
3.15 Conclusion
Chapter 4: High-Performance Web Frontend Using WebAssembly
4.1 What Is WebAssembly?
4.2 What Are You Building?
4.3 Hello WebAssembly!
Setting Up the Development Environment
Creating the Project
Creating the Frontend
4.4 Resizing an Image with WebAssembly
Loading an Image File onto the 
Passing the Image to Wasm
4.5 Writing the Whole Frontend in Rust
4.6 A Hello World Example
4.7 A Cat Management Application
CSS Styling
Deleting Files
4.8 Wasm Alternatives
4.9 Conclusion
Chapter 5: REST APIs
5.1 What Are You Building?
5.2 Hello Backend World!
5.3 Serving Static Files
5.4 Converting the Cats List to a REST API
5.5 Using a Database
5.6 Adding Cats with a POST Command
5.7 API Testing
5.8 Building the Cat Detail API
5.9 Input Validation
5.10 Error Handling
Using the actix_web::error Helpers
Using a Generic Error That Has Implemented the ResponseError Trait
Using a Custom-Built Error Type
5.11 Customizing the web::Path Extractor Error
5.12 Logging
5.13 Enabling HTTPS
5.14 Framework Alternatives
5.15 Conclusion
Chapter 6: Going Serverless with the Amazon AWS Rust SDK
6.1 What Are You Building?
6.2 What Is AWS Lambda?
6.3 Registering an AWS Account
6.4 Hello World in Lambda
6.5 The Full Architecture
6.6 Using the AWS Serverless Application Model (AWS SAM)
6.7 Setting Up AWS SAM CLI Credentials
6.8 Creating the Catdex Serverless Project
6.9 Building the Upload API
6.10 Building the /cats API
6.11 Uploading the Image Using S3 Pre-signed URL
6.12 Adding the Frontend
6.13 A Note on Security
6.14 Next Steps
6.15 Conclusion
Chapter 7: Building a Game
7.1 What Are We Building?
7.2 Bevy and the Entity Component System Pattern
7.3 Creating a Bevy Project
7.4 See the World Through a Camera
7.5 Adding the Cats
7.6 Loading a Spritesheet
7.7 Moving the Cats
7.8 Creating the Ball
7.9 Can’t Defy Gravity
7.10 Making the Ball Bounce
7.11 Keeping Score
7.12 Let There Be Music
7.13 Alternatives
7.14 Conclusion
Chapter 8: Physical Computing in Rust
8.1 What Are You Building?
8.2 Physical Computing on Raspberry Pi
Getting to Know Your Raspberry Pi
Installing Raspberry Pi OS Using Raspberry Pi Imager
Installing the Rust Toolchain
Understanding the GPIO Pins
Building an LED Circuit
Controlling the GPIO Output with Rust
Reading Button Clicks
8.3 Cross-Compiling to Raspberry Pi
8.4 How Does the GPIO Code Work?
8.5 Where to Go from Here?
Chapter 9: Artificial Intelligence and Machine Learning
9.1 Types of Machine Learning Models
9.2 What Are You Building?
9.3 Introducing linfa and rusty-machine
9.4 Clustering Cat Breeds with K-means
Introduction to the K-means Algorithm
The Training Data
Exporting as a CSV
Moving the Configuration into a File
Setting the Configuration File at Runtime
Visualizing the Data
Details on Adding More Entries
Setting Up K-means
9.5 Detecting Cats Versus Dogs with a Neural Network
Introduction to Neural Networks
Preparing the Training Data and Testing Data
Setting Up the Neural Network Model
Reading the Training and Testing Data
Normalizing the Training Data
Training and Predicting
Making the Prediction
9.6 Alternatives
9.7 Conclusion
Chapter 10: What Else Can You Do with Rust?
10.1 The End Is Just the Beginning
10.2 Server-side Rendered Website
10.3 Web Browser and Crawler
10.4 Mobile
10.5 Operating Systems and Embedded Devices
10.6 The Cloud
10.7 Blockchains and Cryptocurrencies
10.8 Unlimited Possibilities of Rust
Index
df-Capture.PNG