choice!() { /* proc-macro */ }Expand description
Makes a Choice that the compiler checks.
The instructions come first, in a form that noul! takes. The options come second:
- A type that derives
Options. The answer gives a variant. - An object of names and descriptions. The answer gives the name.
- An array of names. The answer gives the name.
- An array of
(name, value)or(name, description, value). The answer gives the value.
Each name is a string literal, so two equal names are a compile error. Each description has
a form of the instructions. Each value is a constant expression of any type, and it is not
sent. A Choice has 1 to 255 options. For options from data, use Choice::new,
Choice::with_descriptions, or Choice::with_values.
ยงExamples
use std::cmp::Ordering;
use system2::{Choice, Options, choice};
#[derive(Debug, Clone, Copy, PartialEq, Options)]
enum Team {
/// Payments, invoices, and refunds.
Billing,
/// Bugs and outages.
Engineering,
}
const TEAM: Choice<Team> = choice!("Which team must answer the ticket?", Team);
const NEXT: Choice<&str> = choice!("What must the agent do?", {
"reply": "Reply to the customer.",
"escalate": "Give the ticket to an engineer.",
});
const LANGUAGE: Choice<&str> = choice!("Which language is the ticket in?", ["en", "de", "fr"]);
const BETTER: Choice<Ordering> = choice!("Which reply is better?", [
("first", "The first reply is better.", Ordering::Less),
("second", "The second reply is better.", Ordering::Greater),
]);