Book Image

Mastering Rust

By : Vesa Kaihlavirta
Book Image

Mastering Rust

By: Vesa Kaihlavirta

Overview of this book

<p>If concurrent programs are giving you sleepless nights, Rust is your go-to language. Being one of the first ever comprehensive books on Rust, it is filled with real-world examples and explanations, showing you how you can build scalable and reliable programs for your organization.</p> <p>We’ll teach you intermediate to advanced level concepts that make Rust a great language. Improving performance, using generics, building macros, and working with threads are just some of the topics we’ll cover. We’ll talk about the official toolsets and ways to discover more. The book contains a mix of theory interspersed with hands-on tasks, so you acquire the skills as well as the knowledge. Since programming cannot be learned by just reading, we provide exercises (and solutions) to hammer the concepts in.</p> <p>After reading this book, you will be able to implement Rust for your enterprise project, deploy the software, and will know the best practices of coding in Rust.</p>
Table of Contents (22 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Installing Rust compiler and Cargo


The Rust toolset has two major components: the compiler (rustc) and a combined build tool or dependency manager (Cargo). This toolset comes in three frequently released versions:

  • Nightly: This is the daily successful build of the master development branch. This contains all the features, some of which are unstable.
  • Beta: This is released every six weeks; a new beta branch is taken from nightly. It contains only features that are flagged as stable.
  • Stable: This is released every six weeks; the previous beta branch becomes the new stable.

Developers are encouraged to mainly use stable. However, the nightly version enables many useful features, which is why some libraries and programs require it.

Using rustup.rs

To make it easier for people in various platforms to download and install the standard tools, the Rust team developed rustup. The rustup tool provides a way to install prebuilt binaries of the Rust toolset (rustc and Cargo) easily for your local user. It also allows installing various other components, such as Rust source code and documentation.

The officially supported way to install Rust is to use rustup.rs:

curl https://sh.rustup.rs -sSf | sh 

This command will download the installer and run it. The installer will, by default, install the stable version of the Rust compiler, the Cargo build tool, and the API documentation. They are installed by default for the current user under the .cargo directory, and rustup will also update your PATH environment variable to point there.

Here's how running the command should look:

If you need to make any changes to your installation, choose 2. But these defaults are fine for us, so we'll go ahead and choose 1. This is what the output should look like afterwards:

Now, you should have everything you need to compile and run programs written in Rust. Let's try it!