macro_rules! crate_version {
(VERSION) => { ... };
(BUILD_TIME) => { ... };
(VERSION => $vis:vis $name:ident) => { ... };
(VERSION => $vis:vis $name:ident, $($c:tt)*) => { ... };
(BUILD_TIME => $vis:vis $name:ident) => { ... };
}Expand description
Helper to create version string or build time for your crate.
Package version with git info is in format {CARGO_PKG_VERSION}-{git btanch}-{git commit}-{debug or release}, like 0.4.0-main-c298bc2-DEBUG.
Should have git installed.
§Example
-
Create a
build.rsin the root dir if not persists, and use this macro in the main func. The main func should returnResult.-
For a version string, use
crate_version!(VERSION) -
For a build time in RFC3339 format, use
crate_version!(BUILD_TIME).Don’t forget to add
chronoto your build dependencies.
-
-
In your crate, place
crate_version!(VERSION => pub VERSION),crate_version!(VERSION => pub VERSION)where you like.You can even do this:
crate_version!(VERSION => pub VERSION, env!("CARGO_PKG_NAME", "/"))