pub struct Questions { /* private fields */ }Expand description
An insertion-ordered collection of questions sent in one Jev request.
Use the returned handles to retrieve typed answers after decoding. Dynamic
methods validate raw criteria and fill the question ID in
Error::InvalidCriteria; use DynOptions or DynLevels to validate
once up front and reuse them.
use jevrs_core::Questions;
let mut questions = Questions::new();
let urgent = questions.noul_with(
"is_urgent",
"Does this convey urgency?",
"Explicitly time-sensitive",
"No urgency expressed",
)?;
let department = questions.choice_dyn(
"department",
"Which team should handle this?",
[
("billing", Some("Payments, invoicing, refunds")),
("technical", Some("Bugs, outages, integrations")),
("sales", None),
],
)?;
let frustration = questions.score_dyn(
"frustration",
"How frustrated is the customer?",
["Calm", "Frustrated", "Very angry"],
)?;
assert_eq!(questions.len(), 3);
let _ = (urgent, department, frustration);Implementations§
Source§impl Questions
impl Questions
Sourcepub fn new() -> Self
pub fn new() -> Self
Starts a batch when questions will be added individually at runtime.
Use QuestionSet instead when the whole batch is
fixed at compile time.
Sourcepub fn noul(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
) -> Result<Handle<NoulQ>, Error>
pub fn noul( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, ) -> Result<Handle<NoulQ>, Error>
Adds a yes/no question when the instruction alone defines both outcomes.
Use Self::noul_with when explicit yes and no criteria improve the
decision boundary.
§Errors
Returns Error::DuplicateId if id is already in this batch.
Sourcepub fn noul_with(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
yes: &str,
no: &str,
) -> Result<Handle<NoulQ>, Error>
pub fn noul_with( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, yes: &str, no: &str, ) -> Result<Handle<NoulQ>, Error>
Adds a yes/no question when both outcomes need explicit descriptions.
Use Self::noul for a simpler instruction-only question.
§Errors
Returns Error::DuplicateId if id is already in this batch.
Sourcepub fn choice<O: Options>(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
) -> Result<Handle<ChoiceQ<O>>, Error>
pub fn choice<O: Options>( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, ) -> Result<Handle<ChoiceQ<O>>, Error>
Adds a choice question whose Options are known at compile time.
Use Self::choice_dyn when option keys come from configuration or a
database.
§Errors
Returns Error::DuplicateId if id is already in this batch.
Sourcepub fn score<L: Levels>(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
) -> Result<Handle<ScoreQ<L>>, Error>
pub fn score<L: Levels>( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, ) -> Result<Handle<ScoreQ<L>>, Error>
Adds a score question whose ordered Levels are known at compile time.
Use Self::score_dyn when level descriptions are runtime data.
§Errors
Returns Error::DuplicateId if id is already in this batch.
Sourcepub fn choice_dyn<K, D, I>(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
options: I,
) -> Result<Handle<DynChoiceQ>, Error>
pub fn choice_dyn<K, D, I>( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, options: I, ) -> Result<Handle<DynChoiceQ>, Error>
Adds a choice question backed by runtime-defined DynOptions.
Use this for options loaded from configuration or a database. Prefer
Self::choice when an enum can represent the choices.
§Errors
Returns Error::InvalidCriteria when the options are invalid, with
its id set to this question’s ID. Returns Error::DuplicateId if
id is already in this batch.
Sourcepub fn score_dyn<S: Into<String>>(
&mut self,
id: impl Into<String>,
instructions: impl Into<Instructions>,
levels: impl IntoIterator<Item = S>,
) -> Result<Handle<DynScoreQ>, Error>
pub fn score_dyn<S: Into<String>>( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, levels: impl IntoIterator<Item = S>, ) -> Result<Handle<DynScoreQ>, Error>
Adds a score question backed by runtime-defined DynLevels.
Use this for a scale loaded at runtime. Prefer Self::score when an
enum can represent the ordered levels.
§Errors
Returns Error::InvalidCriteria when the levels are invalid, with its
id set to this question’s ID. Returns Error::DuplicateId if id
is already in this batch.