Search code examples
rustdependenciesversionrust-cargo

How to find the current version of a Rust library?


The Cargo.toml file requires me to state the version of a dependency, e.g. rand = "0.6".

I want to use the package rand_pcg, but don't know the version. How may I find it?


Solution

  • Use the web

    crates.io

    Navigate to https://crates.io/, type your crate name into the search box, and see the version. You can also click the clipboard icon to copy the complete dependency to add to Cargo.toml.

    docs.rs

    Navigate to https://docs.rs/, type your crate name into the search box, and see the version. If you click through to the crate, you can then click the clipboard icon to copy the complete dependency to add to Cargo.toml.

    lib.rs

    Navigate to https://lib.rs/, type your crate name into the search box, and see the version. If you click through to the crate, you can then click on the "installation" tab to see the complete dependency to add to Cargo.toml.

    Use the command line

    cargo build

    Add the wildcard dependency to your Cargo.toml (e.g. rand_pcg = "*"). Run cargo build and note the version it picked (e.g. Compiling rand_pcg v...) or look in Cargo.lock for the entry for the crate. Edit Cargo.toml to use this version.

    cargo add

    Install cargo edit then run cargo add rand_pcg. This is my preferred route.

    See Is there a command to automatically add a crate to my Cargo.toml? for more.

    cargo search

    As mentioned by user2722968, you can run cargo search rand-pcg and it will output the dependency line.