Skip to main content

version_info

Macro version_info 

Source
macro_rules! version_info {
    () => { ... };
}
Expand description

Capture the calling crate’s version into a VersionInfo.

Expands to VersionInfo::from_pkg_version applied to env!("CARGO_PKG_VERSION"). Because macro_rules! expands at the call site, the env! is evaluated while your crate is compiled and therefore yields your version.

This has to be a macro. A plain function cannot do it: the env! inside a function body is expanded when the defining crate is compiled, so it would always report rtb-app’s version. That is exactly the bug VersionInfo::from_env has, and why it is deprecated.

let v = rtb_app::version_info!();
assert_eq!(v.version.to_string(), env!("CARGO_PKG_VERSION"));

Chain the fluent setters to add build metadata:

let v = rtb_app::version_info!()
    .with_commit("deadbeef")
    .with_date("2026-08-02T00:00:00Z");
assert_eq!(v.commit.as_deref(), Some("deadbeef"));