GitHub

Introduction

Installation

I use a Mac, so this may or may not be helpful for you depending on your preferred OS. This is how I installed the tools required for programming in Rust.


Getting cargo

I just went to the official site and hit the "Get started" button on the home page. The Get Started page has a nice simple command to get the latest stable version of Rust installed on your machine

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

The above command will also update the PATH variable, so that you don't have to do it yourself.

Another Option!

I have seen some guides suggesting to visit rustup.rs for installation. I think that's also equally good.

Verify the installation

You can verify if the installation was correctly done using the following command.

cargo --version

That should print the version of cargo installed on your machine. You can also try similar commands. For more info, read this


Creating a new project

Create a sample hello world project

Command

The following command will create a hello folder. It will also initialize a git repository.

cargo new hello

File structure

  • Cargo.toml - Config file
  • target/ - Folder where the build artifacts are put after running cargo run

Semantic Versioning

To know more about version inside your config file visit semver.org

Sample Program & Execution

The following is the code in main.rs file created for us

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

To compile and run this file, run the command cargo run. When using this command the output files will be stored inside target/debug directory

Compilation is only done if the file is changed.

Use cargo run --release to compile without debug symbols. When using this command the output files will be stored inside target/release directory


Previous
Getting started