rustcrates.git / rete / src / lib.rs
lib.rsannotatedlib.rssource40 lines · 2.0 KB · raw
1//! A Rete rules engine that knows only facts, tests on facts, priority and a
2//! network of shared nodes. What the facts are, what they can be, and what a
3//! rule may do is a [`Domain`], which the host implements.
4//!
5//! A fact is something known. A rule is a list of tests on facts and what to
6//! do when they all hold. The network is the rules with their shared tests
7//! merged: one alpha node per distinct test, and a chain of join nodes per
8//! rule, shared where rules begin alike (Forgy, 1979).
9//!
10//! Some facts are supplied by a source outside the network, and each is a
11//! round trip. A rules engine would ask for them one at a time, as each rule
12//! came to need one. [`Network::next`] does not: it collects every such fact
13//! that any rule still alive is waiting on, and returns them together as
14//! [`Next::Ask`], so the host sends one request with N questions. The other
15//! facts are taught by a rule's effect ([`Domain::teaches`]).
16//!
17//! Nothing here does I/O or is async. [`Network::next`] says what to do, and
18//! the host does it and records what it learned in [`Known`]. For a host
19//! that can answer synchronously, [`Network::run`] is that loop, with the
20//! source of each fact as a [`Host`] callback, and it records a [`Trace`] of
21//! which rule fired and what it stood on, as data a host can log.
22//!
23//! Rules are written in code ([`Rule`], usually a `const`) or loaded as data
24//! ([`load`]), and loading is validated against the domain's vocabulary: an
25//! unknown fact, a value the fact cannot have, or an effect the domain does
26//! not allow fails at load, so a bad rule cannot be run.
27#![forbid(unsafe_code)]
28
29mod domain;
30mod load;
31mod network;
32mod trace;
33
34pub use domain::{Domain, Known, Rule, Test, Then};
35pub use load::{LoadError, LoadedRule, Problem, Spec, TestSpec, ThenSpec, export, load, load_specs};
36pub use network::{Join, Network, Next, State, Terminal};
37pub use trace::{Event, Firing, Host, Outcome, Record, Run, Trace};
38
39#[cfg(test)]
40mod tests;