The cargo new
Command
The cargo new
command is used to create a new Rust project as a new directory.
Example: cargo new
% cargo new myproj1
Created binary (application) `myproj1` package
% cd myproj1
% ls -l
total 8
-rw-r--r-- 1 c2ctechtv staff 176 Jul 18 23:27 Cargo.toml
drwxr-xr-x 3 c2ctechtv staff 96 Jul 18 23:27 src
The cargo new
command generated the directory for the project as well as the Cargo.toml file as well as the source folder containing main.rs file.
The cargo init
Command
The cargo init
command is used to initialize an existing directory as a Rust project. You can think of it as a git init command.
Example: cargo init
% mkdir myproj2
% cd myproj2
% cargo init
Created binary (application) package
% ls -l
total 8
-rw-r--r-- 1 c2ctechtv staff 176 Jul 18 23:34 Cargo.toml
drwxr-xr-x 3 c2ctechtv staff 96 Jul 18 23:34 src
Code2care@Mac %
As you can see, I created a folder named myproj2 first then did a cd
followed by cargo init
this generated the directory for the project as well as the Cargo.toml file as well as the source folder containing main.rs file.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Rust: Cargo Init vs Cargo New Command
- Rust: Write and Run Hello World! Program Example
- How to Split a String using Rust Language
- How to Sort a Vector in Rust with Examples
- Fix: error: could not find `Cargo.toml` in Users or any parent directory
- How to uninstall Rust Language from Mac/Linux/Ubuntu
- How to update Cargo (Rust Lang)
- Fix: rust-analyzer failed to discover workspace [Visual Studio Code]
- How to install Rust using rustup on macOS/Linux/Ubuntu
- Cargo Watch: To Recompile Rust Project Automatically
- Difference between rustc and cargo build commands
- How to Split a String by Space in Rust
- How to know Rust is Installed on Mac?
- Rust: zsh: no such file or directory: ./main
- How to update Rust on Mac/Linux
- List of Rust Cargo Commands
- How to find version of Cargo in Rust
- Fix: error: mismatched closing delimiter } [Rust]
- Find Difference of two numbers - C-Program
- Microsoft Edge browser error on MAC - This page is having a problem Try coming back to it later - Microsoft
- How to Change the Default Notepad++ Installation Location - NotepadPlusPlus
- macOS: Text to Speech Command - say examples - MacOS
- Program 13: Reverse a String - 1000+ Python Programs - Python-Programs
- How to add Sleep to PowerShell Script - Powershell
- Program 41: Take a year as input and print whether it is a leap year or not [Python] - Python-Programs
- How to Display Current Date and Time in UTC/GMT in Mac Terminal - MacOS