Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Rust Web Development with Rocket

You're reading from   Rust Web Development with Rocket A practical guide to starting your journey in Rust web development using the Rocket framework

Arrow left icon
Product type Paperback
Published in Jun 2022
Publisher Packt
ISBN-13 9781800561304
Length 420 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Karuna Murti Karuna Murti
Author Profile Icon Karuna Murti
Karuna Murti
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: An Introduction to the Rust Programming Language and the Rocket Web Framework
2. Chapter 1: Introducing the Rust Language FREE CHAPTER 3. Chapter 2: Building Our First Rocket Web Application 4. Chapter 3: Rocket Requests and Responses 5. Chapter 4: Building, Igniting, and Launching Rocket 6. Chapter 5: Designing a User-Generated Application 7. Part 2: An In-Depth Look at Rocket Web Application Development
8. Chapter 6: Implementing User CRUD 9. Chapter 7: Handling Errors in Rust and Rocket 10. Chapter 8: Serving Static Assets and Templates 11. Chapter 9: Displaying Users' Post 12. Chapter 10: Uploading and Processing Posts 13. Chapter 11: Securing and Adding an API and JSON 14. Part 3: Finishing the Rust Web Application Development
15. Chapter 12: Testing Your Application 16. Chapter 13: Launching a Rocket Application 17. Chapter 14: Building a Full Stack Application 18. Chapter 15: Improving the Rocket Application 19. Other Books You May Enjoy

Installing the Rust compiler toolchain

Let's start by installing the Rust compiler toolchain. Rust has three official channels: stable, beta, and nightly. The Rust language uses Git as its version control system. People add new features and bug fixes to the master branch. Every night, the source code from the master branch is compiled and released to the nightly channel. After six weeks, the code will be branched off to the beta branch, compiled, and released to the beta channel. People will then run various tests in the beta release, most often in their CI (Continuous Integration) installation. If a bug is found, the fix will be committed to the master branch and then backported to the beta branch. Six weeks after the first beta branch-off, the stable release will be created from the beta branch.

We will use the compiler from the stable channel throughout the book, but if you feel adventurous, you can use the other channels as well. There's no guarantee the program we're going to create will compile if you use another channel though because people add new features and there might be regression introduced in the new version.

There are several ways to install the Rust toolchain in your system, such as bootstrapping and compiling it from scratch or using your OS package manager. But, the recommended way to install the Rust toolchain in your system is by using rustup.

The definition on its website (https://rustup.rs) is very simple: "rustup is an installer for the systems programming language Rust." Now, let's try following these instructions to install rustup.

Installing rustup on the Linux OS or macOS

These instructions apply if you are using a Debian 10 Linux distribution, but if you are already using another Linux distribution, we're going to assume you are already proficient with the Linux OS and can adapt these instructions suitable to your Linux distribution:

  1. Open your terminal of choice.
  2. Make sure you have cURL installed by typing this command:
    curl
  3. If cURL is not installed, let's install it:
    apt install curl

If you are using macOS, you will most likely already have cURL installed.

  1. After that, follow the instructions on https://rustup.rs:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. It will then show a greeting and information, which you can customize; for now, we're just going to use the default setup:
    ...
    1) Proceed with installation (default)
    2) Customize installation
    3) Cancel installation
    >
  3. Type 1 to use the default installation.
  4. After that, reload your terminal or type this in the current terminal:
    source $HOME/.cargo/env
  5. You can confirm whether the installation was successful or not by typing rustup in the Terminal and you should see the usage instruction for rustup.
  6. Now, let's install the stable Rust toolchain. Type the following in the terminal:
    rustup toolchain install stable
  7. After the toolchain has been installed into your OS, let's confirm whether we can run the Rust compiler. Type rustc in the terminal and you should see the instructions on how to use it.

Installing a different toolchain and components

Right now, we have the stable toolchain installed, but there are two other default channels that we can install: nightly and beta.

Sometimes, you might want to use a different toolchain for various reasons. Maybe you want to try a new feature, or maybe you want to test regression in your application against an upcoming version of Rust. You can simply install it by using rustup:

rustup toolchain install nightly

Each toolchain has components, some of which are required by the toolchain, such as rustc, which is the Rust compiler. Other components are not installed by default, for example, clippy, which provides more checks not provided by the rustc compiler and gives code style suggestions as well. To install it is also very easy; you can use rustup component add <component> as shown in this example:

rustup default stable
rustup component add clippy

Updating the toolchain, rustup, and components

The Rust toolchain has a regular release schedule of around every three months (six weeks plus six weeks), but sometimes there's an emergency release for a major bug fix or a fix for a security problem. As a result, you sometimes need to update your toolchain. Updating is very easy. This command will also update the components installed in the toolchain:

rustup update

Besides the toolchain, rustup itself might also be updated. You can update it by typing the following:

rustup self update

Now that we have the Rust compiler toolchain installed in our system, let's write our first Rust program!

You have been reading a chapter from
Rust Web Development with Rocket
Published in: Jun 2022
Publisher: Packt
ISBN-13: 9781800561304
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image