Creating first Rust Project

Got it! Here’s how you can create a Rust project named rust_playground:

1. Create the Project

  1. Open the Terminal in VSCode:

    • Open the integrated terminal in VSCode by going to Terminal > New Terminal from the top menu or by pressing `Ctrl+`` (backtick).

  2. Navigate to Your Desired Directory:

    • Use the cd command to navigate to the directory where you want to create your Rust project.

  3. Create a New Rust Project:

    • Run the following command to create a new Rust project named rust_playground:

      cargo new rust_playground
  4. Navigate into the Project Directory:

    cd rust_playground
  5. Open the Project in VSCode:

    • Open the project directory in VSCode:

      code .

2. Edit the Rust Program

  1. Locate the main.rs File:

    • In VSCode, go to the Explorer view by clicking on the Explorer icon in the sidebar or by pressing Ctrl+Shift+E.

    • Navigate to src/main.rs. This file contains the default "Hello, world!" code.

  2. Edit main.rs:

    • Open main.rs and you should see the following default code:

      fn main() {
          println!("Hello, world!");
      }
    • You can modify this code if you want to change the output, but the default code will print "Hello, world!" to the console.

3. Run the Rust Program

  1. Run the Program:

    • In the VSCode terminal, make sure you are in the root directory of your project (rust_playground).

    • Run the following command to build and execute your program:

    • This command compiles the Rust code and runs the resulting executable. You should see the output Hello, world! in the terminal.

Summary

  1. Create a new Rust project named rust_playground:

  2. Navigate into the project directory:

  3. Open the project in VSCode:

  4. Edit src/main.rs to write or modify your Rust code.

  5. Run the program using Cargo:

If you have any other preferences or questions, let me know!

Last updated