#[register_rule]
Expand description
This procedural macro registers a decorated function with conjure_rules
’ global registry, and
adds the rule to one or more RuleSet
’s.
It may be used in any downstream crate.
For more information on linker magic, see the linkme
crate.
IMPORTANT: Since the resulting rule may not be explicitly referenced, it may be removed by the compiler’s dead code elimination. To prevent this, you must ensure that either:
- codegen-units is set to 1, i.e. in Cargo.toml:
[profile.release]
codegen-units = 1
- The function is included somewhere else in the code
Functions must have the signature fn(&Expr) -> ApplicationResult
.
The created rule will have the same name as the function.
Intermediary static variables are created to allow for the decentralized registry, with the prefix CONJURE_GEN_
.
Please ensure that other variable names in the same scope do not conflict with these.
This macro must decorate a function with the given signature.
As arguments, it excepts a tuple of 2-tuples in the format:
((<RuleSet name>, <Priority in RuleSet>), ...)
For example:
use conjure_core::ast::Expression;
use conjure_core::model::Model;
use conjure_core::rule_engine::{ApplicationError, ApplicationResult, Reduction};
use conjure_core::rule_engine::register_rule;
#[register_rule(("RuleSetName", 10))]
fn identity(expr: &Expression, mdl: &Model) -> ApplicationResult {
Ok(Reduction::pure(expr.clone()))
}
Register a rule with the given rule sets and priorities.