0%

Book Description

75-80 recipes for learning Rust programming

About This Book

  • Learn to build high-performance Rust units and integrate them into your existing application
  • Work through recipes on performance, robustness, security, memory management, and scalability
  • Work through recipes to build foreign function interface with C, JS, and Python

Who This Book Is For

If you want to write Rust programs, then this book is for you. This book is for those who have a basic knowledge of Rust or any programming language. If you are a C/C developer who is migrating to Rust for various reasons, this book is ideal for you.

What You Will Learn

  • Understand system programming language problems and see how Rust provides unique solutions
  • Get to know the core concepts of Rust to develop fast and safe applications
  • Explore the possibility of integrating Rust units into existing applications to make them more efficient
  • Achieve better parallelism, security, and performance
  • Explore ways to package your Rust application and ship it for deployment in a production environment
  • Discover how to build web applications and services using Rust to provide high-performance to the end user

In Detail

If you are building concurrent applications, server-side programs, or high-performance applications, you will benefit from this language. This book comes with a lot of application-specific recipes to kick-start your development of real-world high-performance applications with the Rust programming language and integrating Rust units into your existing applications. In this book, you will find some 80 practical recipes written in Rust that will allow you to use the code samples right away in your existing applications. These recipes have been tested with stable rust compiler versions of 1.14.0 and above.

This book will help you understand the core concepts of the Rust language, enabling you to develop efficient and high-performance applications by incorporating features such as zero cost abstraction and better memory management.

We’ll delve into advanced-level concepts such as error handling, macros, crates, and parallelism in Rust. Toward the end of the book, you will learn how to create HTTP servers and web services, building a strong foundational knowledge in server-side programming and enabling you to deliver solutions to build high-performance and safer production-level web applications and services using Rust.

Style and approach

This book helps you learn the core concepts of Rust faster by taking a recipe-based approach, where you can try out different code snippets to understand a concept.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Let us Make System Programming Great Again
    1. Introduction
    2. Setting up Rust in Linux and macOS
      1. Getting ready
      2. How to do it...
        1. Uninstalling Rust
        2. Rust's compiler version
        3. Advanced installation options
        4. Troubleshooting
      3. How it works...
    3. Setting up Rust in Windows
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating your first Rust program
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Defining a variable assignment
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Setting up Boolean and the character types
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Controlling decimal points, number formats, and named arguments
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Performing arithmetic operations
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Defining mutable variables
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Declaring and performing string operations
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Declaring arrays and using slices in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Declaring vectors in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Declaring tuples in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Performing calculations on two numbers
      1. Getting ready
      2. How to do it...
      3. How it works...
  3. Advanced Programming with Rust
    1. Introduction
    2. Defining an expression
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Defining constants
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Performing variable bindings
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Performing type casting in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Decision-making with Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Looping operations in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Defining the enum type
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Defining closures
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Performing pointer operations in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Defining your first user-defined data type
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Adding functionality to the user-defined data type
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Similar functionality for different data type
      1. Getting ready
      2. How to do it...
      3. How it works...
  4. Deep Diving into Cargo
    1. Introduction
    2. Creating a new project using Cargo
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Downloading an external crate from crates.io
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Working on existing Cargo projects
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Running tests with Cargo
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Configuration management of the project
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Building the project on the Travis CI
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Uploading to crates.io
      1. Getting ready
      2. How to do it...
      3. How it works...
  5. Creating Crates and Modules
    1. Introduction
    2. Defining a module in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Building a nested module
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating a module with struct
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Controlling modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Accessing modules
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating a file hierarchy
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Building libraries in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Calling external crates
      1. Getting ready
      2. How to do it...
      3. How it works...
  6. Deep Dive into Parallelism
    1. Introduction
    2. Creating a thread in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Spawning multiple threads
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Holding threads in a vector
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Sharing data between threads using channels
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Implementing safe mutable access
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating child processes
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Waiting for a child process
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Making sequential code parallel
      1. Getting ready
      2. How to do it...
      3. How it works...
  7. Efficient Error Handling
    1. Introduction
    2. Implementing panic
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Implementing Option
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Creating map combinator
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating and_then combinator
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating map for the Result type
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Implementing aliases
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Handling multiple errors
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Implementing early returns
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Implementing the try! macro
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Defining your own error types
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Implementing the boxing of errors
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Hacking Macros
    1. Introduction
    2. Building macros in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Implementing matching in macros
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Playing with common Rust macros
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Implementing designators
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Overloading macros
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Implementing repeat
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Implementing DRY
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Integrating Rust with Other Languages
    1. Introduction
    2. Calling C operations from Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Calling Rust commands from C
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Calling Rust operations from Node.js apps
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Calling Rust operations from Python
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Writing a Python module in Rust
      1. Getting ready
      2. How to do it...
      3. How it works...
  10. Web Development with Rust
    1. Introduction
    2. Setting up a web server
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating endpoints
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Handling JSONRequests
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Building custom error handlers
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Hosting templates
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Advanced Web Development in Rust
    1. Introduction
    2. Setting up the API
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Saving user data in MongoDB
      1. Getting ready
      2. How to do it...
    4. Fetching user data
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Deleting user data
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Advanced Rust Tools and Libraries
    1. Introduction
    2. Setting up rustup
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Setting up rustfmt
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Setting up rust-clippy
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Setting up and testing with Servo
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Generating random numbers
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Writing lines to a file
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Parsing unstructured JSON
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Parsing URL from a string
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Decompressing a tarball
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Compressing a directory to a tarball
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Finding file extensions recursively
      1. Getting ready
      2. How to do it...
      3. How it works...
3.137.172.115