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
impl Engine
pub fn new() -> Self
pub fn with_limits(limits: ResourceLimits) -> Self
Sourcepub fn limits(&self) -> &ResourceLimits
pub fn limits(&self) -> &ResourceLimits
Resource limits configured for this engine.
Sourcepub fn snapshot(&self) -> Result<Vec<u8>, Error>
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)?).
Sourcepub fn from_snapshot(bytes: &[u8]) -> Result<Self, Error>
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.
Sourcepub fn load(
&mut self,
sources: impl IntoIterator<Item = (SourceType, impl Into<String>)>,
) -> Result<(), Errors>
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.
Sourcepub fn update(
&mut self,
repository: Option<&str>,
code: String,
source_type: SourceType,
) -> Result<(), Errors>
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.
Sourcepub fn remove(
&mut self,
repository: Option<&str>,
spec: &str,
effective: Option<&DateTimeValue>,
) -> Result<(), Error>
pub fn remove( &mut self, repository: Option<&str>, spec: &str, effective: Option<&DateTimeValue>, ) -> Result<(), Error>
Remove a temporal spec slice and replan remaining specs.
Sourcepub fn list(&self) -> Vec<ResolvedRepository>
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).
Sourcepub fn show(
&self,
repository: Option<&str>,
spec: &str,
effective: Option<&DateTimeValue>,
) -> Result<Show, Error>
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.
Sourcepub fn source(
&self,
repository: Option<&str>,
spec: Option<&str>,
effective: Option<&DateTimeValue>,
) -> Result<String, Error>
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).