macro
Generate a constant from an identifier
The teaching macro checks for a single identifier and emits a constant declaration. The compiler checks the generated item in the consumer crate. This limited example formats a validated identifier, not arbitrary source text. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/code_generation.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '12\n' Common mistake: Treating successful tokenization as proof that the generated code type-checks.
Formal Syntax & Structure
rust syntaxrust
make_constant!(NAME);Working Example
Example Snippetrust
use teaching_macros::make_constant;make_constant!(LIMIT);fn main() { println!("{}", LIMIT); }