Skip to main content

Language

Trait Language 

Source
pub trait Language {
    // Required methods
    fn name(&self) -> &str;
    fn new_evaluator(&self) -> Arc<dyn Evaluator>;
}
Expand description

One evaluator language a build carries, and the bridge from this crate’s opaque predicate payloads into it.

didbot-policy-regex is expected to answer to "regex". Kept as a trait rather than a hard dependency on any specific evaluator crate: this crate’s job is turning observed records into declarations the core’s tree can be built from, not owning any one evaluator’s compiled-predicate format. A build wires in every Language it ships by passing them to compile_policies.

Required Methods§

Source

fn name(&self) -> &str

The language name a record’s wrapper names to select this evaluator, e.g. "regex". Matched exactly, case-sensitively.

Source

fn new_evaluator(&self) -> Arc<dyn Evaluator>

A fresh evaluator instance for this language, with nothing compiled into it yet.

The actual compiling happens afterward, via didbot_policy::Evaluator::compile on the value this returns – this method’s whole job is handing back something that implements the trait, so compile_policies never needs to know any evaluator crate’s concrete type. One call per policy this language serves: didbot-policy-regex’s evaluator holds exactly one compiled artifact, so this crate constructs one fresh instance per predicate document rather than compiling several predicates into a shared one.

§Returning a shared instance is a promise about CompiledId

A language backed by shared state may return clones of an Arc it holds internally, but only if its evaluator mints a distinct didbot_policy::CompiledId per compile and dispatches evaluate on it. resolve_predicate calls compile once per policy on whatever this hands back, so an evaluator that keeps one artifact and ignores the compiled argument – which the trait permits, and didbot-policy-regex does – has that artifact overwritten by the next policy sharing the instance, and every earlier policy then silently enforces the last one’s predicate instead of its own. That is a fail-open: a policy the tree still routes writes to stops checking what it was written to check. An evaluator with one artifact per instance must therefore get one instance per policy, which is what a fresh construction here gives it.

Implementors§