4 ms·
Rust macros have no access to types at all. Types are essential for any but the most trivial metaprogramming.
by ncmncm 6y ago
Rust macros have no access to types at all. Types are essential for any but the most trivial metaprogramming.
- redrobein 6y agoCan you give a specific example of this?
- raphlinus 6y agoIf you consider the scope of metaprogramming to include both macros and traits (and I do), then this is seriously understating the case. Rust's type system has a Prolog-like core and is Turing complete, so is quite expressive in able hands. A great example of the two features working together is serde, which automatically derives serialization and deserialization code (with custom overridable behavior such as defaults) for a very wide range of types. It's also something like 20-50x faster than Swift's Codable based implementation of JSON.
- ncmncm 6y agoI guess I do, too, now. It has got more powerful since I last looked.