Originally published on php2rust.dev — part of the PHP to Rust course. View this lesson on the original site.

Cargo offers two ways to set up a project: cargo new and cargo init.

  • cargo new, Creates a new project in a new directory. Use this when starting from scratch.
  • cargo init, Initializes a project in the current directory. Use this when you already have a folder and want to turn it into a Rust project.

For an existing directory:

cargo init

This creates Cargo.toml and a src/ directory with main.rs (for a binary project).

For a fresh start with a new folder:

cargo new your_project_name

This creates the same structure inside a new directory. Both commands produce a binary project by default.

What's next

Next: Creating a library with cargo init --lib.

From PHP to Rust — Getting Started with Rust