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
Learning Rust

You're reading from   Learning Rust A comprehensive guide to writing Rust applications

Arrow left icon
Product type Paperback
Published in Nov 2017
Publisher Packt
ISBN-13 9781785884306
Length 308 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Vesa Kaihlavirta Vesa Kaihlavirta
Author Profile Icon Vesa Kaihlavirta
Vesa Kaihlavirta
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Introducing and Installing Rust FREE CHAPTER 2. Variables 3. Input and Output 4. Conditions, Recursion, and Loops 5. Remember, Remember 6. Creating Your Own Rust Applications 7. Matching and Structures 8. The Rust Application Lifetime 9. Introducing Generics, Impl, and Traits 10. Creating Your Own Crate 11. Concurrency in Rust 12. Now It's Your Turn! 13. The Standard Library 14. Foreign Function Interfaces

Installing Rust

As with most languages, Rust is available for a wide number of platforms. It would be impossible to go through installing the compiler on every variant of every operating system. Fortunately, there's an official method of installing Rust, and even though the details may differ slightly, the process is almost the same on all platforms. Therefore, this book will cover installing Rust using rustup on Fedora 27.

https://rustup.rs always contains up-to-date instructions on how to get going on all platforms. On Linux and macOS, it will look something like this:

On Windows, this text is replaced by a link to rustup-init.exe, which is an executable that installs and sets up rustup on Windows.

Installing rustup on Linux

Run the suggested command that is shown at https://rustup.rs. Run this command in a Terminal. The script suggests some defaults and asks you to confirm them. This is roughly what it should look like after completing the whole script:

Note that this script attempts to set up rustup for your user by editing your .profile and .bash_profile files. If you are using a custom setup, such as another shell, you may need to add the source $HOME/.cargo/env command manually.

After finishing this script, you can verify that it worked by logging off and on from your Terminal and verifying that the tools are in your path:

gcc prerequisites

To build any software that links against external libraries, you will need a C compiler and development versions of any libraries you may be linking against. To ensure that things work properly, install the compiler using the standard method for your operating system.

In Fedora, this would be done using the dnf tool:

sudo dnf install -y gcc

If you are unsure whether you have gcc installed, type the following command in a terminal window:

gcc -version  

If gcc is installed, you'll see something like this:

Testing your installation

Open a command-prompt window and type this:

rustc --version  

If everything was installed correctly, you will see something like this:

Integrated Development Environment

To effectively code Rust, you will need at least some sort of text editor. All popular editors are properly supported, so if your favorite is Vim, Emacs, or any of the others, you will find a high-quality Rust extension there. The website https://areweideyet.com/ should give a current view of how things are.

We will cover the lightweight IDE from Microsoft, Visual Studio Code, and its most current Rust extension, called simply Rust. This IDE should work fairly well in all the different desktop environments. Installation instructions and packages for several platforms are available at Visual Studio Code's main site, https://code.visualstudio.com.

  1. Open up Visual Studio Code and go to the Command Palette, either by the View menu or by the keyboard shortcut Ctrl + Shift + P (which may differ between platforms). Type in install extension to look for the proper command, and then select Install Extensions:
  1. After selecting this, type rust into the next field to look for the Rust extension. At the time of writing, the most recent one is made by kalitaalexey:
  1. You can install Rust right away by pressing Install; alternatively, click on the list item itself to show information about the extension first. After installing it, reload the editor. The Rust extension is now installed and ready to use!
You have been reading a chapter from
Learning Rust
Published in: Nov 2017
Publisher: Packt
ISBN-13: 9781785884306
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