macro

option_env! — Read an optional build value

Read an optional Unicode environment variable during compilation. An absent variable gives None; an existing empty value gives Some(""). Invalid Unicode causes a compilation error. Choose a public default or handle absence explicitly. Result: Option<&'static str>. Compile environment: {}; unset: ['BYTEMIND_BUILD_CHANNEL']. Expected output (not executed): 'Channel: local\n' Common mistake: Confusing a missing variable with an empty value, or treating the macro as runtime configuration.

Formal Syntax & Structure

rust syntaxrust
option_env!("NAME")

Working Example

Example Snippetrust
fn main() {    let channel = option_env!("BYTEMIND_BUILD_CHANNEL").unwrap_or("local");    println!("Channel: {channel}");}
Rust Reference