Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

Engine for evaluating Lemma rules.

Pure Rust implementation that evaluates Lemma specs directly from the AST. Uses pre-built execution plans that are self-contained and ready for evaluation.

The engine never performs network calls. External @... references must be pre-resolved before loading — either by including dep files in the file map or by calling resolve_registry_references separately (e.g. in a lemma fetch command).

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Source

pub fn sources(&self) -> &HashMap<String, String>

Source code map (attribute -> content). Used for error display.

Source

pub fn with_limits(limits: ResourceLimits) -> Self

Create an engine with custom resource limits.

Source

pub fn load(&mut self, code: &str, source: SourceType<'_>) -> Result<(), Errors>

Load a single spec from source code. When source is SourceType::Dependency, content is treated as from a registry bundle (from_registry: true).

Source

pub fn load_from_paths<P: AsRef<Path>>( &mut self, paths: &[P], from_registry: bool, ) -> Result<(), Errors>

Load .lemma files from paths (files and/or directories). Directories are expanded one level only (direct child .lemma files). Resource limits max_files, max_loaded_bytes, max_file_size_bytes are enforced in [add_files_inner].

Set from_registry to true for pre-fetched registry bundles (same rules as Context::insert_spec with from_registry). Not available on wasm32 (no filesystem).

Source

pub fn get_spec( &self, spec_id: &str, effective: Option<&DateTimeValue>, ) -> Result<Arc<LemmaSpec>, Error>

Resolve spec_id (name or name~hash) and effective (or now if None) to the loaded spec.

Source

pub fn get_plan_hash( &self, spec_id: &str, effective: &DateTimeValue, ) -> Result<Option<String>, Error>

Plan hash for a spec execution plan resolved by spec_id and effective datetime.

Source

pub fn remove( &mut self, spec_id: &str, effective: Option<&DateTimeValue>, ) -> Result<(), Error>

Remove the temporal version resolved by spec_id (name or name~hash) and effective (or now if None).

Source

pub fn list_specs(&self) -> Vec<Arc<LemmaSpec>>

All specs, all temporal versions, ordered by (name, effective_from).

Source

pub fn list_specs_effective( &self, effective: &DateTimeValue, ) -> Vec<Arc<LemmaSpec>>

Specs active at effective (one per name).

Source

pub fn schema( &self, spec: &str, effective: Option<&DateTimeValue>, ) -> Result<SpecSchema, Error>

Resolve spec identifier (name or name~hash) and return the spec schema. Uses effective or now when None.

Source

pub fn get_plan( &self, spec_id: &str, effective: Option<&DateTimeValue>, ) -> Result<&ExecutionPlan, Error>

Resolve spec identifier and return the execution plan. Uses effective or now when None.

With pin (name~hash): resolves spec by (name, hash) from the plan hash registry. If effective is given, verifies it falls within the pinned slice’s [valid_from, valid_to). Without pin: resolves by (name, effective) temporal slice.

Source

pub fn run_plan( &self, plan: &ExecutionPlan, effective: &DateTimeValue, fact_values: HashMap<String, String>, record_operations: bool, ) -> Result<Response, Error>

Run a plan from [get_plan]: apply fact values and evaluate all rules.

When record_operations is true, each rule’s [RuleResult::operations] will contain a trace of facts used, rules used, computations, and branch evaluations.

Source

pub fn run( &self, spec_id: &str, effective: Option<&DateTimeValue>, fact_values: HashMap<String, String>, record_operations: bool, ) -> Result<Response, Error>

Run a spec: resolve by spec id, then [run_plan]. Returns all rules; filter via Response::filter_rules if needed.

When record_operations is true, each rule’s [RuleResult::operations] will contain a trace of facts used, rules used, computations, and branch evaluations.

Source

pub fn invert( &self, spec_name: &str, effective: &DateTimeValue, rule_name: &str, target: Target, values: HashMap<String, String>, ) -> Result<InversionResponse, Error>

Invert a rule to find input domains that produce a desired outcome.

Values are provided as name -> value string pairs (e.g., “quantity” -> “5”). They are automatically parsed to the expected type based on the spec schema.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more