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 (include dependency sources in the source map, or drive crate::Resolve with a host crate::HttpTransport) before loading.

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Source

pub fn with_limits(limits: ResourceLimits) -> Self

Source

pub fn limits(&self) -> &ResourceLimits

Resource limits configured for this engine.

Source

pub fn snapshot(&self) -> Result<Vec<u8>, Error>

Serialize this engine (parsed specs + execution plans + limits) to bytes.

Format: postcard header (LEMS magic + crate version) then a CRC32-protected postcard body. Same sources loaded into two engines produce identical bytes.

Typical use: std::fs::write(path, engine.snapshot()?) then later Engine::from_snapshot(&std::fs::read(path)?).

Source

pub fn from_snapshot(bytes: &[u8]) -> Result<Self, Error>

Restore an engine from Self::snapshot bytes.

Rejects wrong magic, engine version mismatch, CRC failure, or corrupt body with Error. Does not re-load the embedded stdlib (it is inside the snapshot). After restore, run / show / list / update / remove work as on a live engine.

Source

pub fn load( &mut self, sources: impl IntoIterator<Item = (SourceType, impl Into<String>)>, ) -> Result<(), Errors>

Load Lemma sources in one planning pass. Pairs are (source_type, source_text).

Provenance is derived solely from SourceType: SourceType::Path and SourceType::Volatile are workspace-local; SourceType::Dependency tags repositories with that dependency id.

Source

pub fn update( &mut self, repository: Option<&str>, code: String, source_type: SourceType, ) -> Result<(), Errors>

Replace identities present in code in a single planning pass.

Parses code under source_type. Each parsed identity is inserted or replaced by exact (repository, name, effective_from). For SourceType::Path and SourceType::Dependency, live specs with the same source_type that are absent from code are removed in the same apply — including when code has zero specs (remove every live row of that source). SourceType::Volatile never prunes siblings and requires at least one spec in code.

When repository is Some(name), every staged spec’s repository name must equal name.

Source

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

Remove a temporal spec slice and replan remaining specs.

Source

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

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

Returns listed spec rows (metadata only, no AST, no source text).

Source

pub fn show( &self, repository: Option<&str>, spec: &str, effective: Option<&DateTimeValue>, ) -> Result<Show, Error>

Spec interface and resolved temporal window at effective.

Show.data lists every declared promptable slot. Empty ShowData::needed_by_rules means offered for reuse (data x: alias.slot), not needed by this spec’s remaining rules after normalize. Lemma source text is Self::source.

Source

pub fn source( &self, repository: Option<&str>, spec: Option<&str>, effective: Option<&DateTimeValue>, ) -> Result<String, Error>

Formatted canonical Lemma source for a repository or one spec slice.

When spec is None, returns all specs in the repository sorted by name/effective. When spec is Some, effective selects the temporal slice (default: now).

Source

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

Evaluate a spec.

Source§

impl Engine

Source

pub fn quality(&self) -> Vec<Recommendation>

Structural quality Recommendations across all loaded specs and their relationships.

Advisory only: never affects planning or evaluation. Skips dependency repositories (embedded stdlib and @owner/repo imports).

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Engine

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Engine

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.