#[non_exhaustive]pub struct BuildInfo {
pub name: &'static str,
pub version: &'static str,
pub commit: &'static str,
pub commit_short: &'static str,
pub dirty: Option<bool>,
pub built_at: &'static str,
pub profile: &'static str,
pub target: &'static str,
pub rustc: &'static str,
pub features: &'static str,
}Expand description
Facts fixed when the application was compiled. Get it with
build_info!; every field is a &'static str in the
binary, so it costs nothing at run time.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: &'static strThe application’s CARGO_PKG_NAME.
version: &'static strThe application’s CARGO_PKG_VERSION.
commit: &'static strThe full commit hash, or "unknown".
commit_short: &'static strThe first 7 characters of the commit, or "unknown".
dirty: Option<bool>Whether uncommitted changes to tracked files were built; None when unknown.
built_at: &'static strThe build time, RFC 3339 UTC, or "unknown".
profile: &'static str"release", "debug".
target: &'static strThe target triple, or "unknown".
rustc: &'static strThe rustc version, or "unknown".
features: &'static strThe enabled features, comma-separated and sorted.
Implementations§
Source§impl BuildInfo
impl BuildInfo
Sourcepub fn public(&self) -> PublicBuild<'_>
pub fn public(&self) -> PublicBuild<'_>
Only the name and version, for output that leaves your control (a public health endpoint): commit hashes and toolchain versions help an attacker fingerprint a deployment (threat T11).
let public = sys_lib::build_info!().public().to_string();
assert!(public.starts_with("sys-lib "));Sourcepub fn write_kv(&self, out: &mut impl Write) -> Result
pub fn write_kv(&self, out: &mut impl Write) -> Result
Writes build.name=site build.version=0.3.0 ..., without allocating.
let mut line = String::new();
sys_lib::build_info!().write_kv(&mut line)?;
assert!(line.starts_with("build.name=sys-lib "));Sourcepub fn write_json(&self, out: &mut impl Write) -> Result
pub fn write_json(&self, out: &mut impl Write) -> Result
Writes one JSON object, without allocating; dirty is null when unknown.
let mut json = String::new();
sys_lib::build_info!().write_json(&mut json)?;
assert!(json.starts_with(r#"{"name":"sys-lib","#));Trait Implementations§
impl Copy for BuildInfo
Source§impl Display for BuildInfo
site 0.3.0 (9db9e36, release, built 2026-10-21T18:02:11Z); unknown parts
are left out, and a dirty build shows 9db9e36-dirty.
impl Display for BuildInfo
site 0.3.0 (9db9e36, release, built 2026-10-21T18:02:11Z); unknown parts
are left out, and a dirty build shows 9db9e36-dirty.