![]() ![]() Vague versions also create a second, counter-intuitive problem. When you specify maximally "compatible" requirements, you will get the outdated versions. If an existing project has a lockfile and adds your crate, Cargo will keep old versions of existing dependencies as long as they're "compatible". You may surprised how many crates following a "best practice" of imprecise versions end up specifying versions that are too low, and are incompatible.Ĭargo may pick older versions, even in normal circumstances. Or to test a specific downgraded dependency (and this works on stable): cargo update -p serde -precise 1.0.0 If you want to be maximally flexible with the versions you specify, please actually test them! (preferably in CI): cargo +nightly -Z minimal-versions update I know people use vague versions with good intentions to give flexibility to downstream users, but this backfires! Your crate may get a 5-year-old version of a dependency you've never tested. The crates-io ecosystem has popular crates that add new public APIs even in "patch" releases, so even a "1.0" requirement isn't specific enough, despite intentions of the semver spec. It's easy to accidentally depend on a feature added sometime after the x.0.0 version. ![]() Such overly-flexible version is very likely to be wrong, because it allows Cargo to use a completely different version from the version that you were using and testing against. Cargo also unifies versions with the same semver-major number, so when two crates specify different versions, the higher version will be used for both (note that Cargo's behavior is quite different from npm's - specifying full versions is not a good idea in npm, but is fine in Cargo).īut DO NOT use imprecise depdendency requirements like: serde = "1" # bad It is future-proof: the specified version is only the the minimum version, and still allows upgrades of minor versions. When you specify dependency requirements, please include the minor version, and for some crates also the patch version: serde = "1.0.130" # good!Ĭargo works well with versions specified this way. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |