Skip to main content

Action

Trait Action 

Source
pub trait Action<Context>:
    Describe
    + Clone
    + Copy
    + Eq {
    type Error;

    // Required method
    fn run(&self, _ctx: &mut Context) -> Result<(), Self::Error>;

    // Provided methods
    fn select() -> Result<Self, Error> { ... }
    fn select_with_prompt<S>(prompt: S) -> Result<Self, Error>
       where S: Display { ... }
    fn multiselect<S>(values: Vec<Self>) -> Result<Vec<Self>, Error> { ... }
    fn multiselect_with_prompt<S>(
        prompt: S,
        values: Vec<Self>,
    ) -> Result<Vec<Self>, Error>
       where S: Display { ... }
}
Expand description

An enumerable command that can be presented to the user as an interactive CLI selection and then executed against a shared Context.

Required Associated Types§

Source

type Error

Error type returned when running the action fails.

Required Methods§

Source

fn run(&self, _ctx: &mut Context) -> Result<(), Self::Error>

Executes the selected action, mutating the shared Context as needed.

Provided Methods§

Source

fn select() -> Result<Self, Error>

Prompts the user to pick a single action using the type’s default caption.

Source

fn select_with_prompt<S>(prompt: S) -> Result<Self, Error>
where S: Display,

Prompts the user to pick a single action using the supplied prompt text.

Source

fn multiselect<S>(values: Vec<Self>) -> Result<Vec<Self>, Error>

Prompts the user to pick multiple actions using the default caption, pre-selecting values.

Source

fn multiselect_with_prompt<S>( prompt: S, values: Vec<Self>, ) -> Result<Vec<Self>, Error>
where S: Display,

Prompts the user to pick multiple actions using the supplied prompt text, pre-selecting values.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§