Auto deriving HTML forms from structs / enums

This is a variant of Debug/Display/Serde. I'm going to start with a few examples, then post the question.

pub struct Pet {
  name: String,
  age: usize,
  legs: usize

We want this to become a HTML form with 3 labels (name / age / legs), and 3 input boxes.

pub struct Gender {
  Male, Female }

we want this to be come a combobox select box w/ two options: Male, Female

pub struct Enemy {
  Zombie { hp: usize, speed: f32 },
  Terrorist { hp: usize, speed: f32, ammo: u32 }

This becomes a combo box with "Zombie / Terrorist", and depending on the selected option, either 2 label-inputbox or 3 label-inputbox.

Now the question, is there any library that auto derives this where we an just do a #[derive(Form)] and it generates these forms for us.

It need not be HTML. It can be Tui, Egui, ... whatever-gui. I'm just interested in studying procedural macros that do "Rust struct/enum" <=> "gui widgets".


How about reflection?

Have you looked at html_compile?

I would recommend using the function build_component from this library.