First, I have a bunch of functions foo1, foo2, bar1, bar2, etc.
Next, I want each function to have some metadata bundled with it in a way that can be read at runtime and used when each function is called. I'd also like the metadata to be defined alongside the function to keep things from getting out of sync during refactoring, as well as for easy perusal of the source.
Originally I planned on a struct with both the metadata and a function pointer containing a lambda defining the function right there in the struct. However this hit a snag...The metadata structs are static (one copy per library), and the functions are generic - and only made concrete by consumers of the library, ergo no function pointers.
I've been experimenting with macros, and maybe that's the best way to go.
I could simply put the call to t.bar(m) in each and every function, but I'd prefer not to clutter up those functions (there are a lot of them). MyTrait also has other functions generally useful to each function beyond the metadata function "bar".
I suspect it’ll get optimized out because the actual function that needs to be called is known within the function, but there’s obviously no guarantees.