Re:Solving Advent of Code at Compile Time with Rust Macros
by MeetingsBrowser on Saturday December 14, 2024 @07:09PM
(#42420434)
Is this really what Rust macros look like?
[ Parent
| on HN ]
Re:Solving Advent of Code at Compile Time with Rust Macros
by p4ul on Saturday December 14, 2024 @11:31PM
(#42421467)
This is one kind of macro in Rust: declarative macros [1]. The other kind of macros in Rust are procedural macros [2]. Both are widely used in idiomatic Rust. And even within the procedural type of macros, there are different categories of macros (i.e., function-, or attribute-like macros).
[1] https://doc.rust-lang.org/book/ch19-06-macros.html
[2] https://doc.rust-lang.org/book/ch19-06-macros.html#procedura...
Re:Solving Advent of Code at Compile Time with Rust Macros
by C-programmer on Saturday December 14, 2024 @11:48PM
(#42421531)
Yes, and I've seen them in production. Once you learn the rules, you can parse them reasonably well in your head but it is still really confusing at a glance.
Re:Solving Advent of Code at Compile Time with Rust Macros
by CodeBrad on Sunday December 15, 2024 @10:57AM
(#42424088)
It is! Although they are being used in a really weird and not normal way here.
I found "The Little Book of Rust Macros"[1] to be a really good resource for getting started with Rust's declarative macros.