Answer

Enum Answer 

Source
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>)

§Yes

§

No(Option<&'a str>)

§No

§

Retry(Option<&'a str>)

§Retry

§

Next(Option<&'a str>)

§Next

§

Cancel(Option<&'a str>)

§Cancel

§

UserDefined(T)

§User-defined

Trait Implementations§

Source§

impl<'a, T> Debug for Answer<'a, T>
where T: Eq + PartialEq + Hash + Display + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for Answer<'_, T>
where T: Eq + PartialEq + Hash + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T> Hash for Answer<'_, T>
where T: Eq + PartialEq + Hash + Display,

Source§

fn hash<H>(&self, h: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T> PartialEq for Answer<'_, T>
where T: Eq + PartialEq + Hash + Display,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> Eq for Answer<'a, T>
where T: Eq + PartialEq + Hash + Display + Eq,

Auto Trait Implementations§

§

impl<'a, T> Freeze for Answer<'a, T>
where T: Freeze,

§

impl<'a, T> RefUnwindSafe for Answer<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Answer<'a, T>
where T: Send,

§

impl<'a, T> Sync for Answer<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Answer<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for Answer<'a, T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.