What are Cargo and Cargo.toml in Rust?

Created Jan 25, 2024Last modified Jan 25, 2024

Rust Basics


cargo is the command-line tool that comes with Rust. It is used for various tasks related to managing Rust projects. Cargo handles tasks like building the project, downloading and managing dependencies, running tests, and creating documentation.

common commands

Example workflow:

# Create a new project
cargo new my_project

# Navigate to the project directory
cd my_project

# Build and run the project
cargo run

# Run tests
cargo test

# Initialize in an existing folder
cargo init

Cargo simplifies many aspects of Rust development, making it easy to get started and manage projects, dependencies, and builds.


Cargo.toml is the manifest file for a Rust project. It contains metadata about the project, such as its name, version, dependencies, and other settings.

The file is written in TOML (Tom's Obvious, Minimal Language), which is a configuration file format that's easy to read due to its simple syntax.

Example Cargo.toml file:

name = "my_project"
version = "0.1.0"
authors = ["Your Name <your@email.com>"]
edition = "2021"

rand = "0.8.5"