3 ms·
> I’m surprised rust went with macros instead of something like comptime - though I assume there’s some trade offs I’m not aware of. Rust has procedural macros
by akiselev 6y ago
> I’m surprised rust went with macros instead of something like comptime - though I assume there’s some trade offs I’m not aware of.
Rust has procedural macros which are Rust libraries built and run compile time that can transform raw tokens into valid Rust code (or more raw tokens for nested macros). Procedural macros can annotate any statement or code block - although some specific ones might still be on nightly only.
- _nhynes 6y agocrate-level inner attribute macros are still unsupported [0], so if you want those, you'll need to do the codegen before the compiler takes a pass or from within the compiler itself (using, say an after_parsing [1] hook). They're really helpful for making a deeply embedded DSL. [0] https://github.com/rust-lang/rust/issues/54726 https://github.com/rust-lang/rust/issues/54726 [1] https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html#method.after_parsing https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver...