Skip to main content

noul

Macro noul 

Source
noul!() { /* proc-macro */ }
Expand description

Makes a Noul that the compiler checks.

The macro never fails at run time: every mistake is a compile error, pointing at the bad token. The instructions come first, in one of three forms:

  • A string literal. It works as a format string, like format!, where each placeholder names a variable, as in {name}. The text outside the placeholders can’t be only whitespace. A literal with no placeholders makes a constant.
  • A &'static str constant, such as include_str!("rule.txt"). cargo check validates it.
  • A JSON literal, { … } or [ … ], that is not empty, with no key repeated. Each string value is a format string. Any other value is a literal, or a variable of a type that always serializes: text, a number, a bool, a serde_json::Value, a serde_json::Map, or a collection or string-keyed map of those.

The optional criteria come second: an object with a "true" key, a "false" key, or both, where each criterion takes any of the forms above. If the instructions come from data, use Noul::new instead.

§Examples

use system2::{Noul, noul};

const URGENT: Noul = noul!("Is the ticket urgent?");
const REFUND: Noul = noul!("Does the customer ask for a refund?", {
    "true": "The customer wants the money back.",
    "false": "The customer wants no money.",
});
const POLICY: Noul = noul!({
    "question": "Does the reply obey the policy?",
    "policy": "A reply never promises a date.",
});

let product = "the mobile app";
let about = noul!("Is the ticket about {product}?");