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]
- Go to Line Number option in Windows Notepad - NotepadPlusPlus
- [JEP 430] Java JDK 21 New Feature - String Templates (Preview) - Java-JDK-21
- 29: Program to move a file in Python - Python
- Handling NullPointerException with Java Predicate - Java
- Calculate Volume of Cone - C-Program
- Android Emulator 5.1.1 not loading on Mac OS X Android Studio - Android-Studio
- How to change the System Settings Sidebar icon size Mac Ventura 13 - MacOS
- How to Sync iPhone with iPad - iOS