4 ms·
Rust macros are more powerful than CPP in many ways, e.g. pattern matching and nice variadics. Much easier to write, use and document than either a C macro or C
by dbaupp 11y ago
Rust macros are more powerful than CPP in many ways, e.g. pattern matching and nice variadics. Much easier to write, use and document than either a C macro or C++ templates (although the later is definitely improving in the newest standards).
These sorts of macros work very well for large classes of things one would do in with those C/C++, and more beyond that too. Syntax extensions are particularly good at things that not possible without massive hacks in either (although, again, this is somewhat changing with constexpr in C++14 etc).
On the point of being inline, yes, it would be helpful sometimes, but often syntax extensions are "standalone": useful functionality that makes sense to be in its own crate (e.g. for publishing to crates.io), especially while they are unstable. And cargo makes it so easy to use other crates (even local ones, even plugins) that it barely matters where it is defined in terms of tooling/infrastructure.