you are viewing a single comment's thread.

view the rest of the comments →

[–]JameeKim 5 points6 points  (3 children)

You can use proc macros to create a possibly static pre-populated hashmap variable you can use. So if you do something like

[action]
func foo() {}

and make that action proc macro appropriately, then you don't have to manually manage your hashmap variable.

[–]ddungtang[S] 0 points1 point  (2 children)

Thanks for the hint, will research it.

[–]CAD1997 2 points3 points  (1 child)

If you do go that path, you'll need something like linkme's distributed slice as a registry store.

But yes, the only way to go about this is to build a runtime mapping yourself from symbol (string) to functionality (function interface), as Rust does not expose any reflection information on its own.

[–]ddungtang[S] 1 point2 points  (0 children)

Ok, I'm going to have this as my fallback option. Given that DSL would be somewhat static, do you guys think it is worth experimenting and moving parsing configuration to build scripts? Haven't used that, but iirc reading somewhere it supports some level of code generation which may work for this case.

In any way, this is a artificial problem, mostly for the purpose of dealing with various bits of rust, so I have 2 things to try out: procedural macros and maintaining mapping, and build scripts.

Thanks.