2 Project management with Cargo

 

This chapter covers

  • Introducing Cargo and how to manage Rust projects with Cargo
  • Handling dependencies in Rust projects
  • Linking to other (non-Rust) libraries
  • Publishing Rust applications and libraries
  • Documenting Rust code
  • Following the Rust community’s best practices for managing and publishing projects
  • Structuring Rust projects with modules and workspaces
  • Considerations for using Rust in embedded environments

Before we can jump into the Rust language itself, we need to familiarize ourselves with the basic tools required to work with Rust. This may seem tedious, but I can assure you that mastering tooling is critical to success. The tools were created by the language creators for the language users to make your life easier, so understanding their purpose will forever pay dividends.

Rust’s package management tool is called Cargo, and it’s the interface to Rust’s compiler rustc, the https://crates.io registry, and many other Rust tools (which we cover in more detail in chapter 3). Strictly speaking, it’s possible to use Rust and rustc without using Cargo, but it’s not something I’d recommend for most people.

When working with Rust, you’ll likely spend a lot of time using Cargo and tools that work with Cargo. It’s important to familiarize yourself with its use and best practices. In chapter 3, I’ll provide recommendations and details on how to further increase the usefulness of Cargo with community crates.

2.1 Cargo tour

2.1.1 Basic usage

2.1.2 Creating a new application or library

2.1.3 Building, running, and testing

2.1.4 Switching between toolchains

2.2 Dependency management

2.2.1 Handling the Cargo.lock file

2.3 Feature flags

2.4 Patching dependencies

2.4.1 Indirect dependencies

2.4.2 Best practices for dependency patching

sitemap