Rust Getting started with Rust Minimal example

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

To write the traditional Hello World program in Rust, create a text file called hello.rs containing the following source code:

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

This defines a new function called main, which takes no parameters and returns no data. This is where your program starts execution when run. Inside it, you have a println!, which is a macro that prints text into the console.

To generate a binary application, invoke the Rust compiler by passing it the name of the source file:

$ rustc hello.rs

The resulting executable will have the same name as the main source module, so to run the program on a Linux or MacOS system, run:

$ ./hello
Hello World!

On a Windows system, run:

C:\Rust> hello.exe
Hello World!


Got any Rust Question?