No, macros can see only the tokens you give them. They have no notion of the fact that crate::functions
is a module, that PluginFunction
is a trait and that functions_map
is a variable. Not even the compiler may know those informations when the macro is expanded.
If you really really want to do this, you can use something like inventory
. Note that inventory
uses a special linker section to do this, which some consider a hack. This is also not supported on WASM if you want to target it.
Zig is safer than C, but not on a level that is comparable to Rust, so it lacks its biggest selling point. Unfortunately just being a more modern language is not enough to sell it.
C++ was not added to Linux because Linus Torvalds thought it was an horrible language, not because it was not possible to integrate in the kernel.