| Crates.io | inquire-derive |
| lib.rs | inquire-derive |
| version | 0.9.1 |
| created_at | 2025-09-16 05:19:29.155962+00 |
| updated_at | 2025-09-16 06:50:36.454434+00 |
| description | Derive macros for the inquire crate |
| homepage | https://github.com/mikaelmello/inquire |
| repository | https://github.com/mikaelmello/inquire |
| max_upload_size | |
| id | 1840985 |
| size | 10,036 |
Derive macros for the inquire crate.
Put these lines in your Cargo.toml, under [dependencies].
inquire = "0.9.1"
inquire-derive = "0.9.1"
Then use the Selectable derive macro on your enums:
use inquire_derive::Selectable;
use std::fmt::{Display, Formatter};
#[derive(Debug, Copy, Clone, Selectable)]
enum Color {
Red,
Green,
Blue,
}
impl Display for Color {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
// Now you can use:
let color = Color::select("Choose a color:").prompt()?;
let colors = Color::multi_select("Choose colors:").prompt()?;
The Selectable derive macro generates two methods for your enum:
select(msg: &str) - Returns a Select builder for single selectionmulti_select(msg: &str) - Returns a MultiSelect builder for multiple selectionBoth methods return builders that can be customized before calling .prompt():
let color = Color::select("Choose a color:")
.with_help_message("Use arrow keys to navigate")
.with_page_size(5)
.prompt()?;
let colors = Color::multi_select("Choose colors:")
.with_default(&[0, 1]) // Pre-select first two options
.with_help_message("Space to select, Enter to confirm")
.prompt()?;
Run the examples to see the derive macro in action:
cargo run --example enum_select_derive
cargo run --example enum_comprehensive
Your enum must implement:
Display - for showing options to the userDebug - required by inquireCopy and Clone - for efficient handling'static - for the generated code