pub trait CodeExecutor: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn capabilities(&self) -> BackendCapabilities;
fn supports_language(&self, lang: &ExecutionLanguage) -> bool;
fn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn restart<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn is_running<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Async trait for code execution backends.
Backends may optionally implement lifecycle methods (start,
stop, restart) for persistent execution
environments like containers. The default implementations are no-ops, so
simple backends (e.g., host-local rustc) work without lifecycle management.
Backends that support persistent environments should override these methods
and report supports_persistent_workspace: true in their capabilities.
Required Methods§
Sourcefn capabilities(&self) -> BackendCapabilities
fn capabilities(&self) -> BackendCapabilities
The capabilities this backend can enforce.
Sourcefn supports_language(&self, lang: &ExecutionLanguage) -> bool
fn supports_language(&self, lang: &ExecutionLanguage) -> bool
Whether this backend supports the given language.
Sourcefn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
request: ExecutionRequest,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute a request and return a structured result.
Provided Methods§
Sourcefn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Start the execution environment (e.g., create and start a container).
For persistent backends, this creates the underlying environment and
makes it ready for execute calls. Calling execute
on a started backend reuses the same environment.
The default implementation is a no-op for backends that don’t need lifecycle management (e.g., host-local compilation).
Sourcefn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Stop the execution environment and release resources.
For persistent backends, this stops and removes the underlying
environment (e.g., stops and removes a Docker container). After
stop, the backend can be restarted with start.
The default implementation is a no-op.