Skip to main content

Host

Trait Host 

Source
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§

Source

fn runtime(&self) -> &Runtime

Source

fn enabled_rules(&self) -> Result<Vec<Self::Rule>, Self::Error>

The enabled rules, in the order they should run.

Source

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?

Source

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.

Source

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.

Source

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).

Source

fn blocked(&self, rule: &Self::Rule, event: &Self::Event, why: &str)

A matching rule was not run (loop: …, too deep: …, limit: …).

Provided Methods§

Source

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.

Source

fn rules_unavailable(&self, _error: &Self::Error)

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".

Implementors§