What a host supplies: the facts its rules are about, the values they can
take, and what a rule may do. A domain is a marker type, so it is Copy
and the engine's types can derive from it.
Names are the vocabulary of rules written as data. They are also what a
[crate::Record] carries, so a name is never content: a fact's name, never
what it was about.
11pub trait Domain: Copy + Debug + Eq + 'static {
Something that can be known. Ordered, so that the facts a request asks for come in a stable order.
14 type Fact: Copy + Ord + Debug + 'static;
What a fact can turn out to be.
16 type Value: Copy + Eq + Debug + 'static;
Something a rule does that teaches a fact ([Domain::teaches]).
18 type Effect: Copy + Eq + Debug + 'static;
How a rule ends the query outright.
20 type End: Copy + Eq + Debug + 'static;
Something that is so when a rule holds, and that decides no step.
22 type Note: Copy + Eq + Debug + 'static;
Every fact, in the order a drawing lists them.
25 fn facts() -> &'static [Self::Fact];
The fact's name: unique among the facts.
27 fn fact_name(fact: Self::Fact) -> &'static str;
Everything the fact can turn out to be, so a test on any other value is refused when a rule is loaded.
30 fn values(fact: Self::Fact) -> &'static [Self::Value];
The value's name: unique among one fact's values.
32 fn value_name(value: Self::Value) -> &'static str;
Whether a source outside the network supplies the fact when asked, in the one request that asks for every such fact together. A fact that is not is taught by an effect.
36 fn asked_for(fact: Self::Fact) -> bool;
The fact an effect teaches. An effect whose fact is already known has been done.
39 fn teaches(effect: Self::Effect) -> Self::Fact;
The effect a rule loaded as data names, or why this domain does not allow it. Refusing is the default: a domain opts each kind in.
As [Domain::parse_effect], for an end.
As [Domain::parse_effect], for a note.
One test on one fact: an alpha node.
The test without its fact's name, as a drawing labels the node.
What a rule does when it holds.
Go and make a call that teaches a fact.
88 Do(D::Effect),
Stop with this.
90 End(D::End),
A rule written in code. Order is priority: of the rules that hold, the first with something left to do decides.
What is known so far.
108impl<D: Domain> Default for Known<D> { 109 fn default() -> Self { 110 Known(BTreeMap::new()) 111 } 112} 113 114impl<D: Domain> Known<D> { 115 pub fn learn(&mut self, fact: D::Fact, value: D::Value) { 116 self.0.insert(fact, value); 117 } 118 119 pub fn get(&self, fact: D::Fact) -> Option<D::Value> { 120 self.0.get(&fact).copied() 121 } 122 123 pub fn forget(&mut self, fact: D::Fact) { 124 self.0.remove(&fact); 125 }