$ Rust tutorials

Chapter 02

Few things you should know

The Rust API is frequently evolving (read: improving), so this tutorial will be aimed at current master which has the latest language contents.
Note that most of the “standard” features are pretty much stabilized and should not change much. You can choose to use the latest release, but as it gets older, there will probably be numerous changes onto the latest trunk. If you have any concern related to the language or its syntax, just jump on IRC and ask the others!

The latest release is Rust 0.9, released on January 9th 2014.

Installing Rust

Windows

You can get snapshot builds for Windows through the NuGet Package Manager console:

Install-Package Rust

Or have a look at the build instructions if you want to build it yourself.
Note: mingw-w64 should fix a few things compared to the regular mingw (it works on both 32- and 64-bit systems, despite the name).

If you are not willing to go through these steps, just download the 0.9 release.

Mac OS X

The installation process on Mac OS is fairly easy using the Homebrew package manager; for the latest trunk, run:

brew install --HEAD rust

And to get the latest release:

brew install rust

Linux

Okay Linux users, let’s build the beast:

git clone https://github.com/mozilla/rust.git
cd rust
./configure
make
sudo make install

And for the 0.9 release, use these sources:

curl -O http://static.rust-lang.org/dist/rust-0.9.tar.gz
tar -xzf rust-0.9.tar.gz
cd rust-0.9
./configure
make
sudo make install

Note that there are repositories with nightly packages for Arch, Fedora and Ubuntu.

Get your code editor ready

You are about to write your first Rust program; just create a .rs file with your favorite text editor. It gets built with rustc, the Rust compiler.

# create a new file
touch hello.rs
# now compile it...
rustc hello.rs
# ...and run!
./hello

Using the -O switch will add the default optimization level to the code.

BTW, you can get syntax highlighting for vim, gedit or other highlighting solutions on the main repo.