You worked hard to build your Rust library. You followed best practices, took advantage of those expressive yet concise language constructs, pulled in rock-solid dependencies instead of reinventing the wheel...
Your library is useful; its API lean and to the point, generic where it makes sense. Even your unit test coverage is decent!
You're ready to publish it for the world to enjoy.
But what version of Rust does it really require?
Maybe you're one of those fearless explorers who live on nightly. Or maybe you use the latest stable but keep it up-to-date as soon as a new release comes out so you can take take advantage of those sweet-sweet goodies that just about every new version delivers!
Before Rust 1.56, you'd have to informally document the version that you thought was required; for example, the one that you used to build your crate, or retroactively determined by installing older versions of Rust. Your users would then have to follow this advice.
However, starting with version 1.56 Rust allows crate authors to specify their Minimum Supported Rust Version as rust-version in Cargo.toml.
Nice! Yet the original problem persists -- what version should you enter into that field?
If you go with the version that you're currently on, then it's possible you're unnecessarily forcing your users to that version or newer.
On the other hand, constraining yourself to an older version doesn't bring much joy (unless of course you have a specific audience in mind).
Ready to dive into shell and whip up a for-loop to install every possible Rust version to see which one breaks the build?
Before getting overcome by despair, have a look at cargo-msrv -- this little gem of a tool figures it all out for you!
First, install it like you would any other cargo subcommand; e.g.:
cargo install cargo-msrv
Then, let it determine which Rust version your crate actually requires based on your code as well as your dependencies:
cargo msrv
Et violà:
Determining the Minimum Supported Rust Version (MSRV) for toolchain aarch64-apple-darwin
Using check command cargo check
Check for toolchain '1.61.0-aarch64-apple-darwin' succeeded
Check for toolchain '1.58.1-aarch64-apple-darwin' succeeded
Check for toolchain '1.57.0-aarch64-apple-darwin' succeeded
Check for toolchain '1.56.1-aarch64-apple-darwin' succeeded
Finished The MSRV is: 1.56.1 ██████████████████████████████████████████████████████████████████████████████████████████████████████████ 00:00:45
Not only that; it'll also tell you why an earlier version would break the build! That way, you can decide if this is something that you can change or work around in order to support an older Rust version, thus potentially reaching a wider audience.
Once you've set your Cargo.toml's rust-version
to the recommended value, you can verify that it still holds as you continue developing your crate:
cargo msrv verify
The tool offers a lot more helpful features.
Kudos to the author and thanks to all those who contributed; I was delighted to have discovered this very useful tool!
Top comments (0)