How to create a macro from dynamic content


Been playing with macro for a while, but I am having a hard time figuring out how to write a macro that generates a code based on a content that is only available dynamically.

Say I retrieved the flowers from some API or database

let flowers = ["Rose","Tullip", "Orchid"];

and I want to create a macro that generates the code like this.

enum Flower{

What’s the easiest way to do this?


I think this is in general impossible: macros in Rust (unlike lisp) exist only at the compile time. However, if you write a compiler plugin, you can at the compile time for example query a database. I believe diesel does something similar.