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
impl Engine
pub fn new() -> Self
Sourcepub fn sources(&self) -> &HashMap<String, String>
pub fn sources(&self) -> &HashMap<String, String>
Source code map (attribute -> content). Used for error display.
Sourcepub fn with_limits(limits: ResourceLimits) -> Self
pub fn with_limits(limits: ResourceLimits) -> Self
Create an engine with custom resource limits.
Sourcepub fn load(&mut self, code: &str, source: SourceType<'_>) -> Result<(), Errors>
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).
Sourcepub fn load_from_paths<P: AsRef<Path>>(
&mut self,
paths: &[P],
from_registry: bool,
) -> Result<(), Errors>
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).
Sourcepub fn get_spec_set(&self, name: &str) -> Option<&LemmaSpecSet>
pub fn get_spec_set(&self, name: &str) -> Option<&LemmaSpecSet>
Name-scoped access to all temporal versions of a spec.
Returns the full LemmaSpecSet (every row and its [effective_from, next) range),
or None when no spec by that name is loaded. This is the primitive for catalog
and version-inventory queries. Point-in-time resolution goes through
Engine::get_spec, which delegates here.
pub fn get_spec( &self, name: &str, effective: Option<&DateTimeValue>, ) -> Result<Arc<LemmaSpec>, Error>
Sourcepub fn list_specs(&self) -> Vec<Arc<LemmaSpec>>
pub fn list_specs(&self) -> Vec<Arc<LemmaSpec>>
All specs ordered by (name, effective_from).
Sourcepub fn list_specs_with_ranges(
&self,
) -> Vec<(Arc<LemmaSpec>, Option<DateTimeValue>, Option<DateTimeValue>)>
pub fn list_specs_with_ranges( &self, ) -> Vec<(Arc<LemmaSpec>, Option<DateTimeValue>, Option<DateTimeValue>)>
All specs paired with their half-open
[effective_from, effective_to) validity ranges.
Same order as Self::list_specs. Each entry is
(spec, effective_from, effective_to); for every spec name, the last
row’s effective_to is None (no successor).
Sourcepub fn list_specs_effective(
&self,
effective: &DateTimeValue,
) -> Vec<Arc<LemmaSpec>>
pub fn list_specs_effective( &self, effective: &DateTimeValue, ) -> Vec<Arc<LemmaSpec>>
Specs active at effective (one per name).
Todo: clone the specs instead of returning references
Consider removing this method: does it make sense to list specs by effective date?
Sourcepub fn schema(
&self,
name: &str,
effective: Option<&DateTimeValue>,
) -> Result<SpecSchema, Error>
pub fn schema( &self, name: &str, effective: Option<&DateTimeValue>, ) -> Result<SpecSchema, Error>
Resolve spec identifier and return the spec schema. Uses effective or now when None.
Sourcepub fn run(
&self,
name: &str,
effective: Option<&DateTimeValue>,
data_values: HashMap<String, String>,
record_operations: bool,
) -> Result<Response, Error>
pub fn run( &self, name: &str, effective: Option<&DateTimeValue>, data_values: HashMap<String, String>, record_operations: bool, ) -> Result<Response, Error>
Run a spec: resolve by SpecSet 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 data used, rules used, computations, and branch evaluations.
Sourcepub fn invert(
&self,
name: &str,
effective: Option<&DateTimeValue>,
rule_name: &str,
target: Target,
values: HashMap<String, String>,
) -> Result<InversionResponse, Error>
pub fn invert( &self, name: &str, effective: Option<&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.
Sourcepub fn get_plan(
&self,
name: &str,
effective: Option<&DateTimeValue>,
) -> Result<&ExecutionPlan, Error>
pub fn get_plan( &self, name: &str, effective: Option<&DateTimeValue>, ) -> Result<&ExecutionPlan, Error>
Resolve spec identifier and return the execution plan. Uses effective or now when None.
Sourcepub fn run_plan(
&self,
plan: &ExecutionPlan,
effective: Option<&DateTimeValue>,
data_values: HashMap<String, String>,
record_operations: bool,
) -> Result<Response, Error>
pub fn run_plan( &self, plan: &ExecutionPlan, effective: Option<&DateTimeValue>, data_values: HashMap<String, String>, record_operations: bool, ) -> Result<Response, Error>
Run a plan from [get_plan]: apply data values and evaluate all rules.
When record_operations is true, each rule’s [RuleResult::operations] will
contain a trace of data used, rules used, computations, and branch evaluations.
pub fn remove( &mut self, name: &str, effective: Option<&DateTimeValue>, ) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Engine
impl RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl UnwindSafe for Engine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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