inquire-derive

Crates.ioinquire-derive
lib.rsinquire-derive
version0.9.1
created_at2025-09-16 05:19:29.155962+00
updated_at2025-09-16 06:50:36.454434+00
descriptionDerive macros for the inquire crate
homepagehttps://github.com/mikaelmello/inquire
repositoryhttps://github.com/mikaelmello/inquire
max_upload_size
id1840985
size10,036
Mikael Mello (mikaelmello)

documentation

https://docs.rs/inquire-derive

README

Latest Version Build status Supported platforms License


inquire-derive

Derive macros for the inquire crate.

Usage

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()?;

Features

The Selectable derive macro generates two methods for your enum:

  • select(msg: &str) - Returns a Select builder for single selection
  • multi_select(msg: &str) - Returns a MultiSelect builder for multiple selection

Both 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()?;

Examples

Run the examples to see the derive macro in action:

cargo run --example enum_select_derive
cargo run --example enum_comprehensive

Requirements

Your enum must implement:

  • Display - for showing options to the user
  • Debug - required by inquire
  • Copy and Clone - for efficient handling
  • Be 'static - for the generated code
Commit count: 776

cargo fmt