pub struct ValueChoice<T> { /* private fields */ }Expand description
A Choice question over values known only at runtime, such as line or record ids.
Each value is sent as its Display text and parsed back with FromStr, so the two
must round-trip. Options carry no descriptions; put what they refer to in the state.
use typesafe_client::{Questions, ValueChoice};
let lines = ["Refunds take 5 days.", "Contact support by email.", "Cancel anytime."];
let document: String = lines
.iter()
.enumerate()
.map(|(i, line)| format!("{i}| {line}\n"))
.collect();
let mut questions = Questions::new();
let line = questions.add(
"line",
ValueChoice::new("Which line says how long refunds take?", 0..lines.len()),
);
// `response.answer(&line)?` returns a `TypedChoice<usize>`.Implementations§
Source§impl<T: Display> ValueChoice<T>
impl<T: Display> ValueChoice<T>
Sourcepub fn new<I>(instructions: impl Into<Content>, values: I) -> Selfwhere
I: IntoIterator<Item = T>,
pub fn new<I>(instructions: impl Into<Content>, values: I) -> Selfwhere
I: IntoIterator<Item = T>,
A Choice over values, asking instructions.
Trait Implementations§
Source§impl<T: Clone> Clone for ValueChoice<T>
impl<T: Clone> Clone for ValueChoice<T>
Source§fn clone(&self) -> ValueChoice<T>
fn clone(&self) -> ValueChoice<T>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for ValueChoice<T>
impl<T: Debug> Debug for ValueChoice<T>
Source§impl<T> IntoQuestion for ValueChoice<T>
impl<T> IntoQuestion for ValueChoice<T>
Source§type Answer = ValueChoice<T>
type Answer = ValueChoice<T>
How the answer is read; the type parameter of the returned
QuestionKey.Source§fn into_question(self) -> Question
fn into_question(self) -> Question
The question as sent on the wire.
Source§impl<T: PartialEq> PartialEq for ValueChoice<T>
impl<T: PartialEq> PartialEq for ValueChoice<T>
Source§impl<T> ReadAnswer for ValueChoice<T>
impl<T> ReadAnswer for ValueChoice<T>
Source§type Output<'a> = TypedChoice<T>
type Output<'a> = TypedChoice<T>
What
SystemOneResponse::answer returns for this key.Source§fn read(id: &str, answer: &Answer) -> Result<TypedChoice<T>, AnswerError>
fn read(id: &str, answer: &Answer) -> Result<TypedChoice<T>, AnswerError>
Reads the answer to question
id, failing when it has the wrong kind or content.impl<T: PartialEq> StructuralPartialEq for ValueChoice<T>
Auto Trait Implementations§
impl<T> Freeze for ValueChoice<T>
impl<T> RefUnwindSafe for ValueChoice<T>
impl<T> Send for ValueChoice<T>
impl<T> Sync for ValueChoice<T>
impl<T> Unpin for ValueChoice<T>
impl<T> UnsafeUnpin for ValueChoice<T>
impl<T> UnwindSafe for ValueChoice<T>
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