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!
More Posts related to Rust,
- 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]
More Posts:
- [Solution] POI: Cannot get a NUMERIC value from a STRING cell - Java
- How To Change Mac Terminal Text Color - MacOS
- Get Current Local Date and Time using Java 8 DateTime API - Java
- Connect to 3270 host IBM Mainframe using Mac Terminal (c3270) - MacOS
- SharePoint List redirect user after submitting form NewForm.aspx - SharePoint
- How to change Ping TTL value on macOS - MacOS
- Mac Shortcut for Fullscreen mode for App Window - MacOS
- Get the total size and number of objects of a AWS S3 bucket and folders - AWS