Updating Cargo.toml with minimal versions
โ Rust ๐ 2026-06-14 ๐ค surdeus ๐๏ธ 1I'm reading Rust for Rustaceans (Gjengset, 2021) and the book recommends setting minimal versions on all the crate dependencies when making library crates. The reason is to not force users to newer versions, to avoid e. g. incompatibility with other crates.
The right strategy is to list the earliest version that has all the things your crate depends on and to make sure that this remains the case even as you add new code to your crate. But how do you establish that beyond trawling the changelogs, or through trial and error? Your best bet is to use Cargoโs unstable -Zminimal-versions flag, which makes your crate use the minimum acceptable version for all dependencies, rather than the maximum. Then, set all your dependencies to just the latest major version number, try to compile, and add a minor version to any dependencies that donโt.
So I have installed cargo-minimal-versions and I'm running cargo minimal-versions check. I have added two dependencies to my dev dependencies to bump minimal versions in transitive dependencies, to fix errors, and the check now passes.
However, I realized that my Cargo.toml still have all the new versions and not the ones that the command downgrades to.
Right now I'm comparing the "Downgrading " output to my Cargo.toml versions, but is there a more automated way?
3 posts - 3 participants
๐ท๏ธ Rust_feed