Rust Create new project



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:


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.


cargo new my-binary --bin

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


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.