macro

env! — Require a compile-time environment value

Read a Unicode environment value from the compiler process, not the running executable. Missing or non-Unicode values cause a compilation error. Use for public build labels, never secrets: embedded values can be recovered from artifacts. Use std::env::var for runtime configuration. Result: &'static str. Compile environment: {'BYTEMIND_BUILD_LABEL': 'training'}; unset: []. Expected output (not executed): 'Build: training\n' Common mistake: Setting the variable only after the executable has been compiled.

Formal Syntax & Structure

rust syntaxrust
env!("NAME") or env!("NAME", "custom error")

Working Example

Example Snippetrust
fn main() {    let label = env!("BYTEMIND_BUILD_LABEL", "Set the public build label");    println!("Build: {label}");}
Rust Reference