Managing Projects with Cargo

Hands-on Rust — by Herbert Wolverson (15 / 120)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Installing and Configuring Your Development Env ironment | TOC | Creating Your First Rust Program 👉

Rust ships with a tool named Cargo that assists with your day-to-day interactions with the language. Cargo handles everything from making projects to fetching packages of pre-made code. It can run your programs and call other tools to fix your code formatting and find common errors. Cargo is a Swiss Army knife — it has a tool for everything.

Cargo derives its name from Rust’s structure. Rust programs are called crates. Collections of crates are managed by Cargo. This section walks you through creating your first Rust project and explores what Cargo can do for you.[7]

The first decision you need to make is, “Where do I put my Rust projects?”

Selecting a “Home” Directory for Your Code

You need to decide where you want to store your Rust projects. I use c:\users\herbert\rust when I’m running Windows — and /home/herbert/rust when running Linux. You may place your projects anywhere you like. I recommend a location that’s easy to find, remember, and type.

If your project directory doesn’t already exist, create it using your regular operating environment tools. Now that you have a home directory selected, let’s add a project to it.

Starting a New Project with Cargo

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.