Skip to main content

Questions

Struct Questions 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn choice_dyn<K, D, I>( &mut self, id: impl Into<String>, instructions: impl Into<Instructions>, options: I, ) -> Result<Handle<DynChoiceQ>, Error>
where K: Into<String>, D: Into<String>, I: IntoIterator<Item = (K, Option<D>)>,

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.

Source

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.

Source

pub fn len(&self) -> usize

Returns the number of questions, for validating or reporting a batch.

Source

pub fn is_empty(&self) -> bool

Reports whether encode would reject this batch as empty.

Trait Implementations§

Source§

impl Default for Questions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.