pub trait QuestionSet: AnswerSet {
// Required method
fn prepared() -> &'static PreparedQuestions;
}Expand description
A question set declared as a type: it knows the questions it asks, and its answers decode into it.
#[derive(QuestionSet)] implements it for a struct with one field per
question, serializing the questions when the program is compiled; see the
derive for the attributes it reads. Client::ask sends one:
use typesafe_sdk::{ChoiceAnswer, Choice, NoulAnswer, Noul, Questions, QuestionSet};
#[derive(QuestionSet)]
struct Ticket {
#[noul(instructions = "Is this about billing?")]
billing: NoulAnswer,
#[choice(options("calm", "angry"))]
tone: ChoiceAnswer,
}
// The same questions, built at run time, are the same bytes.
let built = Questions::new()
.noul("billing", Noul::new().instructions("Is this about billing?"))
.choice("tone", Choice::new(["calm", "angry"]))
.prepare()?;
assert_eq!(Ticket::prepared(), &built);Implementing it by hand takes a 'static set and an AnswerSet
implementation that follows that trait’s contract.
Required Methods§
Sourcefn prepared() -> &'static PreparedQuestions
fn prepared() -> &'static PreparedQuestions
The questions, validated and serialized once for the whole program.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".