In this tutorial, we are using VS Code to write code

To write, compile, and run a Rust: Write HelloWorld program using Visual Studio Code (VS Code), follow these steps

Prerequisites

  1. Install Rust: Make sure Rust is installed on your system. You can verify this by running rustc --version and cargo --version in your terminal. If not installed, follow the previous instructions to install Rust on your computer.
  2. Install VS Code: Download and install Visual Studio Code from the official website.

Create a New Rust Project

  • Open a terminal in VS Code by selecting Terminal > New Terminal from the main menu or by pressing Ctrl+ (Windows/Linux) or Cmd+ (macOS).
  • Go to the directory where you want to create your new Rust project.
  • Run the below command to create a new Rust project named hello_world
cargo new hello_world
  • This will create a new directory named hello_world with a basic Rust project structure.

Open the Project in VS Code

  • In the terminal, navigate to the new project directory
cd hello_world
  • Open the project in VS Code by running
code .

Write the “Hello, World!” Code:

  • VS Code should automatically open the src/main.rs file. If not, navigate to the src folder and open main.rs.
  • You should see the default “Hello, World!” program. It looks like this
fn main() {
    println!("Hello world !!!");
}
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello world !!!");
    }
}
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world !!!");
    }
}
Rust: Write HelloWorld

Build and Run the Program

  • Open the terminal in VS Code.
  • Make sure you are in the root directory of your Rust project (where Cargo.toml is located).
  • Run the following command to build and run your Rust program
cargo run
Build and Run the Program

Rust: Write HelloWorld
Tagged on: