| Crates.io | wizify_derive |
| lib.rs | wizify_derive |
| version | 0.0.2 |
| created_at | 2025-05-25 05:48:34.149898+00 |
| updated_at | 2025-05-28 03:15:43.435358+00 |
| description | A macro library for generating a creation wizard from a struct |
| homepage | |
| repository | https://github.com/CalSimmon/wizify-rs |
| max_upload_size | |
| id | 1688034 |
| size | 21,750 |
Quick and simple tool to generate a creation wizard based directly off a struct. Uses your field name along with dialoguer to provide basic creation and validation tasks. Currently, this only works with structs, but in the future, I want to add in enums for selection prompts.
If you want to see the library in action, clone the repository and run the test-wiz project.
[!WARNING] This project is under active development. Each release may have breaking changes as I develop the library.
In order to generate a creation wizard from a struct, you need to use the Wizard derive macro. Here's an example:
#[derive(Wizard, Debug)]
#[wizard(
begin_msg = "✨ Hello, and welcome to the wizify creation wizard 🐧\n\n",
closing_msg = "\nThat was the demonstration of the wizify creation wizard. 🌛",
prefix = " ❓ => "
)]
struct Testing {
#[wizard(prompt = "Enter your name (Optional)")]
name: Option<String>,
#[wizard(prompt = "Enter your favorite color")]
favorite_color: String,
#[wizard(prompt = "Enter your favorite number between 0 and 9", validation = input < 10)]
favorite_number: i32,
}
As of right now, this only supports basic primitives, but in the future I would like to support custom struct fields as well.
Using #[derive(Wizard)] on the stuct will give you basic functionality right out of the box, but there are some options to make a
beautiful wizard with ease.
On the struct level, there are a couple options that will apply to the wizard as a whole.
By adding #[wizard(begin_msg = "<message>")] or #[wizard(begin_msg = <message>)] to your struct parameters, you can add a message at the beginning or the
end of your creation wizard. These will each be printed once over the entire wizard. By default, these messages do not include any
styling, so you will need to add any newlines that you want.
If you want to add a custom prefix to all prompts in your wizard, you can do that by adding the #[wizard(prefix = "<prefix>")] to your
struct parameters. This will apply to the beginning of every prompt for your fields.
These two options added together will look like this when run:
✨ Hello, and welcome to the wizify creation wizard 🐧
❓ => name: Test
❓ => favorite_color: color
❓ => favorite_number: 0
That was the demonstration of the wizify creation wizard. 🌛
Each of the fields can also be customized to use custom prompts and validation.
Using #[wizard(prompt = "<prompt>")] allows you to override the default which is to use the name of the field. This will only work for the
annotated field.
Using #[wizard(validation = <expression>)] allows you to add in extra validation for your prompt.
[!NOTE] By default, dialoguer will always check the type of your prompt, so you do not need to include that in the validation.
To write a validation, use input to mean what the user inputs into the dialoguer prompt, and your validation will be evaluated based on that.
For instance, in the example above we use validation = input < 10. This will get expanded into:
if input < 10 {
Ok(())
} else {
Err("This input is not valid...")
}
Putting these together, the above earlier example will show this as the full wizard:
✨ Hello, and welcome to the wizify creation wizard 🐧
❓ => Enter your name (Optional): Test
❓ => Enter your favorite color: color
❓ => Enter your favorite number between 0 and 9: 0
That was the demonstration of the wizify creation wizard. 🌛
There are a number of upgrades I would like to accomplish in the near future.
Ignore options for fields