pub enum Answer<'a, T>{
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,Hashdo 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
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§
impl<'a, T> Eq for Answer<'a, T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more