“Hello, World!” in Rust!!

Rizwan Akram
3 min readMar 5, 2019

Like every new language, the first thing you learn is to encounter the word “Hello, World!”. It is just the tradition we are still following.

Our task is to print the “hello world” in Rust!, let’s see how we can approach this problem. The first and the simplest way that we will not use in the real world project but at least you should know it. Make sure you have installed rust in your system. It is very easy in Mac and Linux and little tricky in windows. Windows user have to additionally install visual C++ build tools. If struct, go through this link.

Now I am assuming that you have installed rust. Check it by running command “rustc”.

Create a new file and name it “test.rs” and open it in your favorite browser.

fn here stands for function and “fn main( )” here is the main entry point of the program, println! is a macro not a function (these things will be explained later). Next step is to compile the rust program using the “rustc filename” command.

finally after compiling you will get the executable that you can run on any pc

Finally, we are able to print “hello world!” in this language.

But this is not the way we will write our projects. Rust comes with “CARGO” cargo is the same as “NPM”(node package manager in javascript). From now onwards we will use cargo to initiate our project.

To start the Cargo project we can use the command “cargo new file_name”, or if you are already in a directory use command “cargo init”.

After this command folder structure will look like below:

Let’s explore the files we get in the complete cargo project, we have a source folder which has the “main.rs” file which is the entry point of the program with the main function. We have a special file that you can see Is “Cargo.toml” file which is the same as package.json in node project. It keeps the record of all the dependencies installed.

To run our cargo project we have a built-in command i.e, “cargo run”

Let us run it.

Here we have build the project also we have run it. We can only build it by “cargo build’ command.

When we run the command “cargo run” it compiles the program and also creates a new folder target where we will get the executable of the program.

From the next part, we will learn the syntax of the RUST language and explore it more.

Happy Coding!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

--

--