Rust is relatively new systems programming language, which is sponsored by Mozilla Research. Rust is called to be “safe, concurrent and practical language” while supporting functional, imperative-procedural paradigms and object-oriented styles. Performance of Rust is often comparable to idiomatic C++ and Rust’s syntax is also similar to C++.

Rust is also an Open Source language with big part of current commits to language committed by community members.

Installing Rust From Pacman

Rust is available straight from Arch Linux’s package manager pacman, but the recommended way is to install Rust with its own Rustup Toolchain Manager, which is described below.

If you want to install it from pacman run:

$ sudo pacman -S rust

If you use Arch Linux and choose to install Rust this way, you need to update Rust in the future via pacman instead of the rustup.

Rustup is also provided in the pacman package manager:

$ sudo pacman -S rustup

Official Rust Installation

Official and recommended way of installing Rust is with its own Rustup Toolchain Manager. This is recommended over pacman installation since with rustup you can install multiple toolchains (stable, beta, nightly) for multiple targets (windows, mac, android) and architectures (x86, x86_64, arm).

To install Rust you can run the following command and follow the on-screen instructions.

$ curl -f https://sh.rustup.rs > rust.sh

Always read what you are installing when you install softwares from not official repositories. Open the file with your preferred text editor or with command less:

$ emacs rust.sh

After you’re sure of what you’re installing, give the script executable rights and run the script:

$ chmod +x rust.sh 

$ ./rust.sh 
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust programming 
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo's bin 
directory, located at:

  /home/topi/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile files located at:

  /home/topi/.profile
  /home/topi/.bash_profile

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

You can choose to proceed with the default installation (choice 1) or customize it (option 2). For me default options are fine so I chose 1.

To get started you need Cargo’s bin directory ($HOME/.cargo/bin) in your PATH environment variable. Cargo is Rust’s package manager. Next time you log in this will be done automatically.

To configure your current shell, run source $HOME/.cargo/env

Your Rust installation should now be up and running. You can test it immediately with:

$ rustc -V

Which then prints your version of Rust.

We can also test the working of Rust with a simple program:

$ emacs clapton.rs
fn main() {
    println!("Clapton is God!");
}

Rust’s filename extensions are either .rs or .rlib with the latter being used for Rust specific static libraries with various metadata.

Rust also comes with its own compiler called rustc. To compile your program, run:

$ rustc clapton.rs

Rust’s compiler compiles the programs to executable files which you can then run by:

$ ./clapton
Clapton is God!

And Rust seems to be working!

Changing Rust’s Default Toolchain

Above we set stable as our default toolchain, but Rust comes with three different toolchains: nightly, beta and stable.

Rust’s unstable features are available in nightly. So if you’re interested in developing Rust you might want to use this channel. Keeping in mind that these are unstable.

To change your toolchain from stable to nightly you can do it easily by:

$ rustup install nightly

$ rustup default nightly

Updating Rust

If you want to update Rust in the future, you can do that by running:

$ rustup self update

Cargo

Cargo is Rust’s package manager. It allows you to download your Rust project dependencies with it and compiles your project.

To make start a new project with Cargo, run:

$ cargo new --bin hello_world

--bin indicates here that we’re making a binary program. If we would make a library, we would leave that field empty.

$ tree .
.
├── Cargo.toml
└── src
    └── main.rs

Cargo.toml contains the manifest for your project:

[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <[email protected]>"]

[dependencies]

Cargo makes a simple Hello, World to src/main.rs.

fn main() {
    println!("Hello, world!");
}

To compile your Cargo project, run:

$ cargo build
   Compiling hello_world v0.1.0 (file:///home/topi/Projects/Rust/hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 3.14 secs

To run the program, use:

$ cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs Running target/debug/hello_world Hello, world!

Or:

$ ./target/debug/hello_world 
Hello, world!

Read More at