[Solved] Avoid duplicate storing of version

The version of an application typically needs to be in at least two places: the Cargo.toml file and a constant somewhere in order to be displayed to the user.

In other languages we can solve this problem with makefiles of various sorts.

What's the right solution in the cargo world ? Does it still need to be defined ? Should we have a macro reading the Cargo.toml file ?

Cargo sets CARGO_PKG_VERSION environment variable for you:

let version = env!("CARGO_PKG_VERSION");

Doc

6 Likes

Awesome!

This topic was automatically closed after 34 hours. New replies are no longer allowed.