Rust library version data

I was researching if there is a way to query rust library version information at runtime.

I thought I saw some post about cargo adds a uuid into the library that can be read the std rust function. However, I cannot find anything related to that now. So either I’m dreaming, or just can’t get google to cooperate.

I was hoping someone here could help me clarify if and how I can programmatically determine the version of a library built in rust.

Thnx
Matt

Cargo sets env var with library version during the build (https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates), so you can inspect that for your library.

However if the upstream library doesn’t do smth like const LIBRARY_VERSION = env!("CARGO_PKG_VERSION") I don’t think you can get this info.

1 Like

In binary you could; println!(include_str!("../Cargo.lock"));

1 Like