How to Compile and Run Rust Program

This post explains how to compile and run rust Program

For following below instructions rust and VsCode installation is required, if you don't have rust installed, follow link install rust on windows.

  • Create a Project folder from CMD
  • 
    
    E:\rust-tutorials>mkdir first-project
    
    
    
  • Navigate to created folder and open VsCode in it.
  • 
    
    E:\rust-tutorials>cd first-project
    E:\rust-tutorials\first-project>code .
    
    
    
  • Now, in VsCode create a file main.rs and write below code and save the file
  • 
    
    fn main() {
        println!("Hello, rust!");
    }
    
    
    
  • To compile the Rust program , open the terminal and execute below command
  • 
    
    E:\rust-tutorials\first-project>rustc main.rs
    
    
    
  • To run the Rust program, execute below command
  • 
    
    E:\rust-tutorials\first-project>.\main.exe
    
    
    

    Successful execution will print "Hello, rust!" in the terminal


    Follow US on Twitter: