pub enum Answer<'a, T> where
    T: Eq + PartialEq + Hash + Display
{ Yes(Option<&'a str>), No(Option<&'a str>), Retry(Option<&'a str>), Next(Option<&'a str>), Cancel(Option<&'a str>), UserDefined(T), }
Expand description

Answer

For variants which have an optional representation string:

  • If you don’t provide the representation strings, defaults will be used.
  • Implementations of Eq, PartialEq, Hash do NOT work on the representation strings.

For UserDefined:

For example, if you want 2 answers of Resume and Ignore, but there are no such variants, you can do this:

use core::fmt::{self, Display, Formatter};
use dia_args::Answer;

#[derive(Debug, Eq, PartialEq, Hash)]
enum CustomAnswer {
    Resume,
    Ignore,
}

impl Display for CustomAnswer {

    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        f.write_str(match self {
            CustomAnswer::Resume => "Resume",
            CustomAnswer::Ignore => "Ignore",
        })
    }

}

match dia_args::ask_user(
    "What's your desire?",
    &[
        Answer::UserDefined(CustomAnswer::Resume),
        Answer::UserDefined(CustomAnswer::Ignore),
        Answer::Cancel(None),
    ],
)? {
    Answer::UserDefined(answer) => match answer {
        CustomAnswer::Resume => {},
        CustomAnswer::Ignore => {},
    },
    Answer::Cancel(_) => {},
    _ => {},
};

See also

ask_user().

Variants

Yes(Option<&'a str>)

No(Option<&'a str>)

Retry(Option<&'a str>)

Next(Option<&'a str>)

Cancel(Option<&'a str>)

UserDefined(T)

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.