pub fn generate(source: &str, name: &str) -> Result<Generated, Error>Expand description
Generates the struct and the enum for a form.
name is what the struct is called — the file’s stem, usually. See
to_out_dir, which does that part for you.
let form = r#"form "F" version=1 width=200 height=100 {
text-input name=full-name x=0 y=0 w=100 h=30 on-submit=save
checkbox "Notify" name=notify x=0 y=40 w=100 h=20 on-change=set-notify
}"#;
let generated = generate(form, "settings")?;
assert_eq!(generated.kind, "Settings");
assert_eq!(generated.message, "SettingsMessage");
// A kebab name becomes a snake field and a Pascal variant, and the payload
// the widget needs becomes what the variant carries.
assert!(generated.source.contains("pub full_name: ::denise_ui::NodeId"));
assert!(generated.source.contains("Save,"));
assert!(generated.source.contains("SetNotify(bool)"));§Errors
Everything Form::parse can say, plus the three things
only generating code can hit: a name that is not a Rust identifier, two names
that become one identifier, and one message name used with two payload shapes.
Each carries the position in the file.