This is my first post on Rust and on my blog. I’m currently learning Rust and I just thought that I wanted to share my learning with you.

If you are unfamiliar with Rust, please find different resources for the language, like the offical website , the cookbook , on the FAQ , the curated list of resources for Rust maintained by Dystroy. If you are looking for videos instead, these videos provided by Dcode explain Rust well, from fundamentals to more complex topics.

So where do we start?

First things, first, you need to install Rust on your machine. If it is already done, skip to part 2 aka create your next project

Part 1:

Go to the following page :

If you are on Linux or Mac, type the following command line on your bash prompt

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

if you are on Windows, please install the file rustup-init.exe you will have to download from the official website.

Note: The official site of Rust knows if you are on Windows or on Linux. If you are on Windows, it will propose you
to download the binaries and install it on your machine.

Part 2:

Once done, you need to start a project. If like me, you went through Rust official’s doc, you found out there is rustc, the compiler. Although correct, we will run cargo, the package manager. It runs rustc and does some extra work (e.g. resolves dependencies).

To create a new project:

cargo new new_project

The structure of the folder will be like:

	new_project
	├── Cargo.toml
	└── src
	    └── main.rs

The main.rs file is where we are going to put our code.

Part 3:

After editing the main.rs file, you should see the code below.

fn main() {
	println!("Hello World");
    }
}
//print Hello World

To run, the code, type at the root of your new_project :

cargo run

The result below should appear

    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/new_project`
Hello, world!

This is the first step on how to create a new project on Rust.

Tips:

  • println! is a macro. I will discuss this part, much later
  • Almost all commands in rust end with a ; (semi-colon)
  • If you are unfamiliar with the formatting of Rust code, you can type cargo fmt, your code will be formatted in a proper way.

You can follow the links below, which give more detail about Cargo, Rustc