Skip to main content

CodeExecutor

Trait CodeExecutor 

Source
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 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn start<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn stop<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn restart<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn is_running<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Available on crate feature code only.
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§

Source

fn name(&self) -> &str

Human-readable backend name.

Source

fn capabilities(&self) -> BackendCapabilities

The capabilities this backend can enforce.

Source

fn supports_language(&self, lang: &ExecutionLanguage) -> bool

Whether this backend supports the given language.

Source

fn execute<'life0, 'async_trait>( &'life0 self, request: ExecutionRequest, ) -> Pin<Box<dyn Future<Output = Result<ExecutionResult, ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Execute a request and return a structured result.

Provided Methods§

Source

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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).

Source

fn stop<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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.

Source

fn restart<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ExecutionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Restart the execution environment.

Equivalent to stop followed by start, but backends may implement this more efficiently (e.g., docker restart).

The default implementation calls stop then start.

Source

fn is_running<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Whether the execution environment is currently running.

Returns true if start has been called and stop has not. For backends without lifecycle management, this always returns true.

Implementors§