pub trait Host {
type Rule: Rule;
type Event: Event;
type Error: Display;
// Required methods
fn runtime(&self) -> &Runtime;
fn enabled_rules(&self) -> Result<Vec<Self::Rule>, Self::Error>;
fn field(
&self,
rule: &Self::Rule,
event: &Self::Event,
field: &str,
) -> Option<Value>;
fn is_related(&self, rule: &Self::Rule, event: &Self::Event) -> bool;
fn begin_run(&self, rule: &Self::Rule, event: &Self::Event) -> Option<i64>;
fn exec(
&self,
rule: &Self::Rule,
event: &Self::Event,
then: &<Self::Rule as Rule>::Then,
) -> Result<String, Self::Error>;
fn finish_run(&self, rule: &Self::Rule, event: &Self::Event, run: &Run);
fn blocked(&self, rule: &Self::Rule, event: &Self::Event, why: &str);
// Provided methods
fn deferred(&self, _field: &str) -> bool { ... }
fn rules_unavailable(&self, _error: &Self::Error) { ... }
}Expand description
What the engine needs from the application.
Required Associated Types§
Required Methods§
fn runtime(&self) -> &Runtime
Sourcefn enabled_rules(&self) -> Result<Vec<Self::Rule>, Self::Error>
fn enabled_rules(&self) -> Result<Vec<Self::Rule>, Self::Error>
The enabled rules, in the order they should run.
Sourcefn field(
&self,
rule: &Self::Rule,
event: &Self::Event,
field: &str,
) -> Option<Value>
fn field( &self, rule: &Self::Rule, event: &Self::Event, field: &str, ) -> Option<Value>
The value of a field on an event (None: absent).
For related rules: is the event about where the rule lives?
Sourcefn begin_run(&self, rule: &Self::Rule, event: &Self::Event) -> Option<i64>
fn begin_run(&self, rule: &Self::Rule, event: &Self::Event) -> Option<i64>
A run starts (record it, say); the returned id comes back in Run::action.
Sourcefn exec(
&self,
rule: &Self::Rule,
event: &Self::Event,
then: &<Self::Rule as Rule>::Then,
) -> Result<String, Self::Error>
fn exec( &self, rule: &Self::Rule, event: &Self::Event, then: &<Self::Rule as Rule>::Then, ) -> Result<String, Self::Error>
Do one then-action; its message on success.
Sourcefn finish_run(&self, rule: &Self::Rule, event: &Self::Event, run: &Run)
fn finish_run(&self, rule: &Self::Rule, event: &Self::Event, run: &Run)
A run ended (every then-action was tried, in order, whatever the others did).
Provided Methods§
Sourcefn deferred(&self, _field: &str) -> bool
fn deferred(&self, _field: &str) -> bool
Fields that cost something to read (an outside call): read only when the rule could otherwise run, never in a dry check of a rule that does not apply.
The rules could not be listed; nothing runs for this event.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".