Rust Hello World

Rust Programming

Rust Programming

In this tutorial, you will learn to write a "Hello World" program in Rust.

Procedure to write first program.

  • Step 1: Create a RustApp folder and navigate to that folder on terminal. (Using File manager)
  • Step 2: Create folder using terminal.
C:\Users\Admin>mkdir RustApp
C:\Users\Admin>cd RustApp
  • Step 3: To create a Rust file, execute the following command

Rust program files have an extension .rs. The above command creates an empty file and opens it in Notepad. Add the code given below to this file. 


fn main() {
    println!("Hello, World!");

Compile the file using rustc.



Hello, World!{codeBox}


The above program defines a function main fn main(). The fn keyword is used to define a function. The main() is a predefined function that acts as an entry point to the program. println! is a predefined macro in Rust. It is used to print a string (here Hello) to the console. Macro calls are always marked with an exclamation mark – !.

What is a macro?

Rust provides a powerful macro system that allows meta-programming. As you have seen in the previous example, macros look like functions, except that their name ends with a bang(!), but instead of generating a function call, macros are expanded into source code that gets compiled with the rest of the program. Therefore, they provide more runtime features to a program unlike functions. Macros are an extended version of functions.

Credits & Copyrights©: Javatpoints & programiz

Post a Comment