Skip to main content

register_rule

Attribute Macro register_rule 

Source
#[register_rule]
Expand description

This procedural macro registers a decorated function with conjure_cp_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 registration, see the inventory crate.


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_cp_core::ast::Expression;
use conjure_cp_core::ast::SymbolTable;
use conjure_cp_core::rule_engine::{ApplicationError, ApplicationResult, RuleEffect};
use conjure_cp_core::rule_engine::register_rule;

#[register_rule("RuleSetName", 10)]
fn identity(expr: &Expression, symbols: &SymbolTable) -> ApplicationResult {
  Ok(RuleEffect::pure(expr.clone()))
}

Register a rule with the given rule sets and priorities.