pub struct Questions { /* private fields */ }Expand description
The named questions of one request.
All questions see the same state and are answered independently and in parallel, so ask every question about a state in one request, including speculative ones.
use typesafe_client::{NoulQuestion, Questions, ScoreQuestion};
let mut questions = Questions::new();
let refund = questions.add("refund_requested", NoulQuestion::new("Is the user asking for a refund?"));
let anger = questions.add("frustration", ScoreQuestion::new("How frustrated is the user?", ["Calm", "Frustrated", "Very angry"]));
assert_eq!(questions.len(), 2);
assert_eq!(refund.id(), "refund_requested");Implementations§
Source§impl Questions
impl Questions
Sourcepub fn add<Q: IntoQuestion>(
&mut self,
id: impl Into<String>,
question: Q,
) -> QuestionKey<Q::Answer>
pub fn add<Q: IntoQuestion>( &mut self, id: impl Into<String>, question: Q, ) -> QuestionKey<Q::Answer>
Adds question under id and returns a key that reads its answer with the
matching type.
The id is only used to match answers to questions; it is not sent to the model,
so the question itself must carry its full meaning. Ids must be unique: adding a
second question with the same id replaces the first, and Questions::validate
reports the duplicate.
Sourcepub fn iter(&self) -> Iter<'_, String, Question> ⓘ
pub fn iter(&self) -> Iter<'_, String, Question> ⓘ
Questions with their ids, in the order they were added.
Sourcepub fn validate(&self) -> Result<(), ValidationError>
pub fn validate(&self) -> Result<(), ValidationError>
Checks the documented limits: at least one question, unique ids, 1 to 255 Choice options, and 2 to 10 Score levels.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Questions
impl<'de> Deserialize<'de> for Questions
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'a> IntoIterator for &'a Questions
impl<'a> IntoIterator for &'a Questions
impl StructuralPartialEq for Questions
Auto Trait Implementations§
impl Freeze for Questions
impl RefUnwindSafe for Questions
impl Send for Questions
impl Sync for Questions
impl Unpin for Questions
impl UnsafeUnpin for Questions
impl UnwindSafe for Questions
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