pub trait ForeignTask:
Send
+ Sync
+ 'static {
type Params: CrossLanguageSafe + Send + Sync + 'static;
type Result: CrossLanguageSafe + Send + Sync + 'static;
// Required method
fn task_id(&self) -> TaskId;
// Provided method
fn config(&self) -> TaskConfig { ... }
}Expand description
A foreign task stub — represents a task implemented in another language.
Unlike Task, a ForeignTask has no run() method because execution
happens in the foreign language worker. The Rust side only creates
invocations that the foreign worker picks up from its language queue.
The CrossLanguageSafe bound on Params and Result ensures that
only JSON-compatible types are used for cross-language serialization.
§Example
use rustvello_core::task::{ForeignTask, CrossLanguageSafe};
use rustvello_proto::config::TaskConfig;
use rustvello_proto::identifiers::TaskId;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct TrainModelParams {
dataset_path: String,
epochs: u32,
}
impl CrossLanguageSafe for TrainModelParams {}
struct TrainModel {
task_id: TaskId,
}
impl ForeignTask for TrainModel {
type Params = TrainModelParams;
type Result = String;
fn task_id(&self) -> TaskId {
self.task_id.clone()
}
}Required Associated Types§
Sourcetype Params: CrossLanguageSafe + Send + Sync + 'static
type Params: CrossLanguageSafe + Send + Sync + 'static
The input parameters type (must be cross-language safe).
Sourcetype Result: CrossLanguageSafe + Send + Sync + 'static
type Result: CrossLanguageSafe + Send + Sync + 'static
The return type (must be cross-language safe).
Required Methods§
Provided Methods§
Sourcefn config(&self) -> TaskConfig
fn config(&self) -> TaskConfig
Per-task configuration (optional override).