Skip to content

cargo guide: guidance around selecting the version of a dependency? #10624

@kevinushey

Description

@kevinushey

Problem

In the cargo guide, the page on dependencies (https://doc.rust-lang.org/cargo/guide/dependencies.html) describes how one can add specific versions of a couple dependencies, e.g. by editing Cargo.toml:

[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"

[dependencies]
time = "0.1.12"
regex = "0.1.41"

and then links to external documentation regarding SemVer and how other / newer versions of packages could be requested.

However, the documentation doesn't provide any specific guidance around how one should normally choose the versions of their dependencies. Is there any existing convention in the community? For example:

  • Prefer using the latest major release?
  • Look at the documentation on crates.io, and make a choice there?
  • Use an external tool to add dependencies to the project?

It might also be worth documenting the use of cargo add, once #2179 becomes part of stable.

It would also be nice if the crate versions chosen in this documentation matched a more current version (regex is currently 1.5.5, based on https://crates.io/crates/regex).

Proposed Solution

  • Consider providing some guidance for users on how dependency versioning should be done.
    • In particular, note if there are any consequences for downstream users if you plan to build a rust library?
  • Document and describe the use of cargo add?

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crate-dependenciesArea: [dependencies] of any kindA-documenting-cargo-itselfArea: Cargo's documentationC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-addS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions