Rust Cargo Create new project

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Library

cargo new my-library

This creates a new directory called my-library containing the cargo config file and a source directory containing a single Rust source file:

my-library/Cargo.toml
my-library/src/lib.rs

These two files will already contain the basic skeleton of a library, such that you can do a cargo test (from within my-library directory) right away to verify if everything works.

Binary

cargo new my-binary --bin

This creates a new directory called my-binary with a similar structure as a library:

my-binary/Cargo.toml
my-binary/src/main.rs

This time, cargo will have set up a simple Hello World binary which we can run right away with cargo run.


You can also create the new project in the current directory with the init sub-command:

cargo init --bin

Just like above, remove the --bin flag to create a new library project. The name of the current folder is used as crate name automatically.



Got any Rust Question?