Chapter 23: Mastering Cargo

Cargo is Rust's official build system and package manager. It simplifies tasks such as creating new projects, managing dependencies, running tests, and publishing crates to Crates.io. Earlier in this book, we introduced Cargo's basic features for building and running programs as well as managing dependencies. Chapter 17 also covered the fundamental package structure (crates and modules).

This chapter delves deeper into Cargo's capabilities. We will explore its command-line interface, recommended project structure, version management, and techniques for building both libraries and binary applications. Additional topics include publishing crates, customizing build profiles, setting up workspaces, and generating documentation.

Cargo is a versatile and complex tool—this chapter focuses on its most essential features. For a comprehensive overview, consult the official Cargo documentation.

Cargo also supports testing and benchmarking code—topics that will be discussed in the next chapter.