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 dependency sources in the source 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 with_limits(limits: ResourceLimits) -> Self

Source

pub fn specs(&self) -> &Context

Source

pub fn specs_mut(&mut self) -> &mut Context

Source

pub fn resolve_effective(raw: Option<&str>) -> Result<DateTimeValue, Error>

Resolve an optional effective datetime string for planning or evaluation.

None or whitespace-only input resolves to DateTimeValue::now. Non-empty invalid strings return a request Error.

Source

pub fn load( &mut self, code: impl Into<String>, source: SourceType, ) -> Result<(), Errors>

Load one Lemma source (workspace; not a tagged dependency).

Source

pub fn load_batch( &mut self, sources: HashMap<SourceType, String>, dependency: Option<&str>, ) -> Result<(), Errors>

Load many sources in one planning pass. Pairs are (source_text, source_id).

dependency: when Some, repositories parsed from these sources are tagged with that id (same as previous load(..., Some(id)) for path bundles).

Source

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

Active LemmaSpec slice for name at the resolved effective instant.

When effective is None, uses the current time. The name must be unique across loaded repositories at that instant (same rule as Self::get_plan with repo: None). For repository scope or all temporal rows, use Self::get_workspace or Self::get_repository.

Source

pub fn list(&self) -> Vec<ResolvedRepository>

Every loaded repository in insertion order (workspace, embedded stdlib EMBEDDED_STDLIB_REPOSITORY, dependencies).

Each ResolvedRepository::repository and every LemmaSpec under ResolvedRepository::specs includes source metadata (start_line, source_type) from load. Inspectable stdlib text: Self::format_repository with "lemma".

Source

pub fn get_workspace(&self) -> ResolvedRepository

Workspace-local repository (name == None).

Source

pub fn get_repository( &self, qualifier: &str, ) -> Result<ResolvedRepository, Error>

Resolve a loaded repository by qualifier string. Matches against repository names (which include @ when present).

Source

pub fn format_repository(&self, repository: &str) -> Result<String, Error>

Canonical Lemma source for every spec in repository, formatted from the in-engine AST.

Source

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

Planning schema for name. When repo is None, the spec must be unambiguous across all loaded repositories; when Some, scoped to that repository qualifier (e.g. "@org/pkg").

Source

pub fn limits(&self) -> &ResourceLimits

Return the resource limits configured for this engine.

Exposed so callers can pass the same limits to DataOverlay::resolve.

Source

pub fn run( &self, repo: Option<&str>, spec: &str, effective: Option<&DateTimeValue>, data_values: HashMap<String, String>, explain: bool, rules: Option<&[String]>, ) -> Result<Response, Error>

Evaluate a spec. When repo is None, the spec must be unambiguous across loaded repositories; when Some, scoped to that repository qualifier (e.g. "@org/pkg").

When explain is true, each requested rule’s [RuleResult::explanation] contains a structural explanation tree; when false, explanations are omitted.

rules scopes which rule results appear in the response. None means all local rules. Some(&[]) is an error. When explain is true, all local rules (and nested uses rules needed for explanation resolution) are evaluated so explanation trees can embed dependency rules.

Source

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

Execution plan for name. When repo is None, the spec must be unambiguous across all loaded repositories; when Some, scoped to that repository qualifier (e.g. "@org/pkg").

Source

pub fn run_plan( &self, plan: &ExecutionPlan, effective: Option<&DateTimeValue>, data_values: HashMap<String, DataValueInput>, explain: bool, rules: Option<&[String]>, ) -> Result<Response, Error>

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

Spec-declared defaults (-> default ...) are applied by the evaluator when the caller does not supply a value for that data path.

rules: None evaluates all local rules in the response; Some(slice) evaluates only those names (Some(&[]) errors). Each name in Some must be a local rule.

When explain is false, only the VM scope runs (requested rules, or all local when None). When explain is true, all local and nested uses rules run so explanation trees have full rule_results, but only the response scope appears in response.results and receives attached explanations.

Source

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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, 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