#generate-html #forms #structs #macro-derive

formy

Provides a derive macro to turn structs into html forms

6 releases

0.2.2 Feb 15, 2021
0.2.1 Feb 7, 2021
0.1.0 Feb 7, 2021

#1998 in Rust patterns

21 downloads per month

MIT license

5KB

formy

A derive macro to generate HTML forms from structs.

Currently in early development, only input with all its attributes is handled right now.

Docs: https://docs.rs/formy/

use formy::Form;

#[derive(Form)]
struct UserLogin {
    #[input(pattern = r"[\w]+")]
    #[label = "Username:"]
    username: String,
    #[input(type = "email", name = "real_email", class="py-4", id = "email")]
    email: String,
    #[input(type = "password")]
    #[label = "Password:"]
    password: String,
    some_field: String,
}

let form = UserLogin::to_html();

TODO:

  • <select>
  • <textarea>
  • <button>
  • <fieldset>
  • <legend>
  • <datalist>
  • <output>
  • <option>
  • <optgroup>

License: MIT


lib.rs:

A derive macro to generate HTML forms from structs.

Currently in early development, only input with all its attributes is handled right now.

Docs: https://docs.rs/formy/

use formy::Form;

#[derive(Form)]
struct UserLogin {
    #[input(pattern = r"[\w]+")]
    #[label = "Username:"]
    username: String,
    #[input(type = "email", name = "real_email", class="py-4", id = "email")]
    email: String,
    #[input(type = "password")]
    #[label = "Password:"]
    password: String,
    some_field: String,
}

let form = UserLogin::to_form();

TODO:

  • <select>
  • <textarea>
  • <button>
  • <fieldset>
  • <legend>
  • <datalist>
  • <output>
  • <option>
  • <optgroup>

Dependencies

~1.5MB
~39K SLoC