Skip to main content

Select

Trait Select 

Source
pub trait Select: Prompt + Sized {
    // Required methods
    fn options() -> &'static [Self];
    fn labels() -> &'static [&'static str];
    fn from_label(label: &str) -> Option<Self>;
}
Expand description

Select one value from a finite set (dropdown/radio button pattern).

This trait represents the conversational equivalent of a dropdown menu or radio button group. It is the natural elicitation mode for enums and categorical fields.

§Example

use elicitation::{Select, Prompt};

#[derive(Debug, Clone, Copy)]
enum Color {
    Red,
    Green,
    Blue,
}

impl Prompt for Color {
    fn prompt() -> Option<&'static str> {
        Some("Choose a color:")
    }
}

impl Select for Color {
    fn options() -> &'static [Self] {
        &[Color::Red, Color::Green, Color::Blue]
    }

    fn labels() -> &'static [&'static str] {
        &["Red", "Green", "Blue"]
    }

    fn from_label(label: &str) -> Option<Self> {
        match label {
            "Red" => Some(Color::Red),
            "Green" => Some(Color::Green),
            "Blue" => Some(Color::Blue),
            _ => None,
        }
    }
}

Required Methods§

Source

fn options() -> &'static [Self]

All valid options for this selection.

Returns a static slice of all possible values. The MCP tool will ensure the user selects one of these options.

Source

fn labels() -> &'static [&'static str]

Human-readable labels for each option.

Returns labels corresponding to each value in options(). These are presented to the user and used to parse their selection.

Source

fn from_label(label: &str) -> Option<Self>

Parse a label back into the type.

Given a label string (from user selection), returns the corresponding value, or None if the label is invalid.

§Arguments
  • label - The label to parse
§Returns

Some(Self) if the label is valid, None otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§