What Are Dev Dependencies in Rust?

Dev dependencies in Rust are test-only crates defined in Cargo.toml to keep production builds lean.

Dev dependencies in Rust are external crates listed in the [dev-dependencies] section of your Cargo.toml file that are only included when running tests or building documentation, not when compiling your final release binary. They allow you to use testing frameworks like rand or tokio without bloating your production build.

[dev-dependencies]
rand = "0.8.5"

To add a dev dependency, run:

cargo add --dev rand