MOCKSTACKS
EN
Questions And Answers

More Tutorials








RUST Hello World Example

To create a Hello World project we will need to do the below steps.

1) Create Folder For Project

Open cmd (Command Prompt) and navigate where you want to create your project.

Use below commands:

C:\Users\user>mkdir HelloWorldApplication
C:\Users\user>cd HelloWorldApplication
C:\Users\user\HelloWorldApplication>


2) Create Rust File

from above cmd (Command Prompt).

Use below command:

C:\Users\user\HelloWorldApplication>notepad HelloWorld.rs


3) Add code to Rust File

once the above code is executed you will see a notepad opened.

Place below code into notepad and save it:

fn main(){
   println!("My first Rust Project: hello World !!");
}

From above steps we know:
  • Rust file extension is: rs
  • Rust project has a main function: fn main()
  • main syntax define an entry point to the application
  • Rust has a predefined functions which are called as macros and are always marked with !


4) Compile application

From cmd (Command Prompt) above.

Use below command:

C:\Users\user\HelloWorldApplication>rustc HelloWorld.rs


5) Verify output after compilation

Upon successful compilation of the application, a new executable file will be generated and it will have the same name of HelloWorld.rs.

Use below command to verify :

C:\Users\user\HelloWorldApplication>dir
You will see below Files:

HelloWorld.exe
HelloWorld.pdb
HelloWorld.rs
If you run HelloWorld.exe you will see below output:

My first Rust Project: hello World !!



Conclusion

In this page (written and validated by ) you learned about Rust Hello World Example . What's Next? If you are interested in completing Rust tutorial, your next topic will be learning about: Rust Comments.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.