0%

Book Description

A practical guide to understanding the latest features of the Rust programming language, useful libraries, and frameworks that will help you design and develop interesting projects

Key Features

  • Work through projects that will help you build high-performance applications with Rust
  • Delve into concepts such as error handling, memory management, concurrency, generics, and macros with Rust
  • Improve business productivity by choosing the right libraries and frameworks for your applications

Book Description

Rust is a community-built language that solves pain points present in many other languages, thus improving performance and safety. In this book, you will explore the latest features of Rust by building robust applications across different domains and platforms.

The book gets you up and running with high-quality open source libraries and frameworks available in the Rust ecosystem that can help you to develop efficient applications with Rust. You'll learn how to build projects in domains such as data access, RESTful web services, web applications, 2D games for web and desktop, interpreters and compilers, emulators, and Linux Kernel modules. For each of these application types, you'll use frameworks such as Actix, Tera, Yew, Quicksilver, ggez, and nom. This book will not only help you to build on your knowledge of Rust but also help you to choose an appropriate framework for building your project.

By the end of this Rust book, you will have learned how to build fast and safe applications with Rust and have the real-world experience you need to advance in your career.

What you will learn

  • Access TOML, JSON, and XML files and SQLite, PostgreSQL, and Redis databases
  • Develop a RESTful web service using JSON payloads
  • Create a web application using HTML templates and JavaScript and a frontend web application or web game using WebAssembly
  • Build desktop 2D games
  • Develop an interpreter and a compiler for a programming language
  • Create a machine language emulator
  • Extend the Linux Kernel with loadable modules

Who this book is for

This Rust programming book is for developers who want to get hands-on experience with implementing their knowledge of Rust programming, and are looking for expert advice on which libraries and frameworks they can adopt to develop software that typically uses the Rust language.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Creative Projects for Rust Programmers
  3. Dedication
  4. About Packt
    1. Why subscribe?
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  7. Rust 2018: Productivity
    1. Technical requirements
    2. Understanding the different editions of Rust
    3. The projects
    4. Working through the examples in this book
    5. Exploring some utility crates
    6. Pseudo-random number generators – the rand crate
    7. Logging – the log crate
    8. Initializing static variables at runtime – the lazy_static crate
    9. Parsing the command line – the structopt crate
    10. Summary
    11. Questions
  8. Storing and Retrieving Data
    1. Technical requirements
    2. Project overview
    3. Reading a TOML file
    4. Using toml_dynamic
    5. Using toml_static
    6. Reading and writing a JSON file
    7. The json_dynamic project
    8. The json_static project
    9. Reading an XML file
    10. Accessing databases
    11. Accessing a SQLite database
    12. Implementing the project
    13. Accessing a PostgreSQL database
    14. Implementation of the project
    15. Storing and retrieving data from a Redis store
    16. Implementing the project
    17. Putting it all together
    18. Summary
    19. Questions
  9. Creating a REST Web Service
    1. Technical requirements
    2. The REST architecture
    3. Project overview
    4. Essential background theory and context
    5. Building a stub of a REST web service
    6. Running and testing the service
    7. Getting a resource using the GET method
    8. Sending a named resource to the server using the PUT method
    9. Sending a new resource to the server using the POST method
    10. Deleting a resource using the DELETE method
    11. Sending an invalid command
    12. Examining the code
    13. Building a complete web service
    14. Downloading a file
    15. Uploading a string to a specified file
    16. Uploading a string to a new file
    17. Deleting a file
    18. Examining the code
    19. Building a stateful server
    20. How to have a stateful server
    21. The API of this service
    22. Testing the service
    23. Implementing the database
    24. Handling queries
    25. Returning JSON data
    26. Summary
    27. Questions
    28. Further reading
  10. Creating a Full Server-Side Web App
    1. Technical requirements
    2. Definition of a web app
    3. Understanding the behavior of a web app
    4. Project overview
    5. Using the Tera template engine
    6. A simple list of persons
    7. The templates folder
    8. The other Rust handlers
    9. A CRUD application
    10. The JavaScript code
    11. The HTML code
    12. The Rust code
    13. The db_access.rs changes
    14. The main.rs changes
    15. Handling an application with authentication
    16. The implementation
    17. The HTML code
    18. The JavaScript code
    19. The mock database code
    20. The main function
    21. Summary
    22. Questions
    23. Further reading
  11. Creating a Client-Side WebAssembly App Using Yew
    1. Technical requirements
    2. Introducing Wasm
    3. Understanding the MVC architectural pattern
    4. Implementing two toy web apps
    5. What is the MVC pattern?
    6. The model
    7. The view
    8. The controller
    9. View implementation
    10. Controller implementation
    11. Understanding the MVC architecture
    12. Project overview
    13. Getting started
    14. The incr app
    15. The adder app
    16. The login app
    17. Organization of the project
    18. The db_access.rs file
    19. The main.rs file
    20. The login.rs file
    21. The yauth app
    22. Understanding the behavior of the app
    23. Organization of the project
    24. The persons_list.rs file
    25. Why an empty collection wouldn't be good for filtered_persons
    26. The one_person.rs file
    27. A web app accessing a RESTful service
    28. The persons_db app
    29. The yclient app
    30. The imported crates
    31. The source files
    32. The changes to the models
    33. A typical client/server request
    34. Summary
    35. Questions
    36. Further reading
  12. Creating a WebAssembly Game Using Quicksilver
    1. Technical requirements
    2. Project overview
    3. Understanding the animation loop architecture
    4. Implementing the ski project
    5. Understanding the code behind this
    6. Implementing the silent_slalom project
    7. Implementing the assets_slalom project
    8. Analyzing the code
    9. Summary
    10. Questions
    11. Further reading
  13. Creating a Desktop Two-Dimensional Game Using ggez
    1. Technical requirements
    2. Project overview
    3. Understanding linear algebra
    4. Implementing the gg_ski project
    5. The main function
    6. Patterns of input handling
    7. Input handling in the gg_ski project
    8. Other differences with quicksilver
    9. Name of the trait
    10. The type of context
    11. The new method
    12. The angle's unit of measurement
    13. How to specify the FPS rate
    14. Handling the ski steering
    15. Computation of new position and speed
    16. Drawing the background
    17. Drawing composite shapes
    18. Ending the draw method
    19. Implementing the gg_silent_slalom project
    20. Implementing the gg_assets_slalom project
    21. Implementing the gg_whac project
    22. The assets
    23. The general structure of the application and events
    24. Other fields of the model
    25. Defining a widget
    26. Summary
    27. Questions
    28. Further reading
  14. Using a Parser Combinator for Interpreting and Compiling
    1. Technical requirements
    2. Project overview
    3. Introducing Calc
    4. Understanding formal languages and their parsers
    5. Regular languages
    6. Context-free languages
    7. Context-dependent languages
    8. Using Nom to build parsers
    9. Learning about compiler-compilers and parser combinators
    10. Learning the basics of Nom
    11. Parsing an alternative of characters
    12. Parsing a sequence of characters
    13. Parsing a fixed string
    14. Mapping parsed items to other objects
    15. Creating custom parsing results
    16. Parsing a variable text
    17. Repeating a parser
    18. The calc_parser project
    19. Understanding the main.rs source file
    20. Learning about the parser.rs source file
    21. Understanding the types needed by the parser
    22. Looking at the parser code
    23. The calc_analyzer project
    24. Checking the variables of the parsed program
    25. Understanding the main.rs file
    26. Looking at the symbol_table.rs file
    27. Glancing at the analyzer.rs file
    28. The calc_interpreter project 
    29. Learning about the main.rs file
    30. Glancing at the symbol_table.rs file
    31. Understanding the executor.rs file
    32. The calc_compiler project
    33. Glancing at the main.rs file
    34. Understanding the compiler.rs file
    35. Summary
    36. Questions
    37. Further reading
  15. Creating a Computer Emulator Using Nom
    1. Technical requirements
    2. Project overview
    3. Introducing a very simple machine language
    4. The most important concepts relating to machine language
    5. Extending our machine language
    6. Writing a very simple program
    7. A more complex program – the sieve of Eratosthenes
    8. Defining a byte-addressing machine language
    9. Coping with the endianness issue
    10. The nom_byte_machine project
    11. Understanding the main.rs source file
    12. Using the Nom library
    13. The emulator.rs source file
    14. The parsing_interpreter.rs source file
    15. The translator.rs source file
    16. The nom_disassembler project
    17. Running the project
    18. Examining the source code
    19. Generating disassembly code that is useful for debugging
    20. Generating disassembly code that is useful for reassembling
    21. Summary
    22. Questions
  16. Creating a Linux Kernel Module
    1. Technical requirements
    2. Project overview
    3. Understanding kernel modules
    4. Preparing the environment
    5. A boilerplate module
    6. Building and running the kernel module
    7. The build commands
    8. The source code of the boilerplate module
    9. Using global variables
    10. Allocating memory
    11. A character device
    12. Building the character device
    13. The source code of the dots module
    14. The global information
    15. The initialization call
    16. The cleanup call
    17. The reading function
    18. Summary
    19. Questions
    20. Further reading
  17. The Future of Rust
    1. IDEs and interactive programming
    2. Crate maturity
    3. Asynchronous programming
    4. Optimization
    5. The const generics feature
    6. Embedded systems
    7. Summary
  18. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
  19. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.22.181.209