How to Use the concat!, stringify!, and env! Macros

Use concat!, stringify!, and env! macros to join literals, convert code to strings, and read environment variables at compile time.

Use concat! to join string literals at compile time, stringify! to turn code into a string literal, and env! to read environment variables at compile time.

let joined = concat!("Hello, ", "world!");
let code = stringify!(let x = 5);
let version = env!("CARGO_PKG_VERSION");

println!("{} {} {}", joined, code, version);

concat! requires all arguments to be string literals. stringify! takes any Rust expression and returns its source code as a string. env! panics at compile time if the specified environment variable is not set.