pub trait LanguageEngine {
// Required methods
fn id(&self) -> &'static str;
fn execute(&self, payload: &ExecutionPayload) -> Result<ExecutionOutcome>;
// Provided methods
fn display_name(&self) -> &'static str { ... }
fn aliases(&self) -> &[&'static str] { ... }
fn supports_sessions(&self) -> bool { ... }
fn validate(&self) -> Result<()> { ... }
fn toolchain_version(&self) -> Result<Option<String>> { ... }
fn start_session(&self) -> Result<Box<dyn LanguageSession>> { ... }
}Expand description
Runtime adapter for a supported programming language.
Implementors validate a real local toolchain, execute one-shot payloads,
and optionally create a persistent LanguageSession for REPL use.
§Example
ⓘ
use anyhow::Result;
use run::engine::{ExecutionOutcome, ExecutionPayload, LanguageEngine};
struct ToyEngine;
impl LanguageEngine for ToyEngine {
fn id(&self) -> &'static str { "toy" }
fn display_name(&self) -> &'static str { "Toy" }
fn validate(&self) -> Result<()> {
// Check that the interpreter/compiler exists and is runnable.
Ok(())
}
fn execute(&self, payload: &ExecutionPayload) -> Result<ExecutionOutcome> {
// Materialize payload input, spawn the toolchain, capture stdout and stderr,
// and return the process exit code and elapsed time.
}
}