How to write Rust Program -in VS Code

Rust

We will write our first program in rust and we will use the universal program which is usually the first program in any language. “Hello World” or “Hello Rust World”.

So open the Visual Studio Code editor and create a new file in it with name “hello” and give it an extension “.rs”. Rust program source code files have “.rs” extension name so we named it with “.rs” extension.

So here is our first program:

main()
{
   println!("Hello Rust World !!");
}

Now save your file when you are done typing your program.

Open the integrated terminal in Visual studio code and then let’s compile our program to create the executables. Use the command below to compile your code.

> rustc  hello.rs

This should compile your file and create the executable file “hello.exe”.

Before you run this executable you can use the “ls” command to make sure you have the “exe” created by the compiler.

Once you have your exe available to you then just execute this on the next line of terminal:

> Hello.exe

You should see the text “Hello Rust World !!” on your terminal. 🙂 🙂