#[derive(Answers)]
{
// Attributes available to this derive:
#[system2]
}
Expand description
Derives Answers for a struct, so that Questions asks the questions of its fields.
The struct has named fields, and no generic parameters. Each field names its question set with
#[system2(question = …)]. The type of the field is the answer set of that question set. The
question set must be a constant expression, such as URGENT or noul!("…"). A named set in a
named set is Questions::new(). For questions from data, use questions!. The derive adds
no method to the struct. A public struct can hold the answer of a private type, such as a
ChoiceAnswer of a private enum.
§Examples
use system2::prelude::*;
use system2::{ChoiceAnswer, NoulAnswer};
#[derive(Debug, Clone, Copy, PartialEq, Options)]
enum Team {
Billing,
Engineering,
}
#[derive(Debug, Answers)]
struct Triage {
#[system2(question = noul!("Is the ticket urgent?"))]
urgent: NoulAnswer,
#[system2(question = choice!("Which team must answer the ticket?", Team))]
team: ChoiceAnswer<Team>,
}
const TRIAGE: Questions<Triage> = Questions::new();
let triage = TRIAGE.ask(ticket).await?;
if triage.urgent.is_likely() && *triage.team.most_likely() == Team::Engineering { /* … */ }