Creating first Rust Project
Got it! Here’s how you can create a Rust project named rust_playground:
1. Create the Project
Open the Terminal in VSCode:
Open the integrated terminal in VSCode by going to
Terminal > New Terminalfrom the top menu or by pressing `Ctrl+`` (backtick).
Navigate to Your Desired Directory:
Use the
cdcommand to navigate to the directory where you want to create your Rust project.
Create a New Rust Project:
Run the following command to create a new Rust project named
rust_playground:cargo new rust_playground
Navigate into the Project Directory:
cd rust_playgroundOpen the Project in VSCode:
Open the project directory in VSCode:
code .
2. Edit the Rust Program
Locate the
main.rsFile: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.
Edit
main.rs:Open
main.rsand 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
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
Create a new Rust project named
rust_playground:Navigate into the project directory:
Open the project in VSCode:
Edit
src/main.rsto write or modify your Rust code.Run the program using Cargo:
If you have any other preferences or questions, let me know!
Last updated