mesh_worker

Trait Worker

Source
pub trait Worker: 'static + Sized {
    type Parameters: 'static + Send;
    type State: 'static + MeshPayload + Send;

    const ID: WorkerId<Self::Parameters>;

    // Required methods
    fn new(parameters: Self::Parameters) -> Result<Self>;
    fn restart(state: Self::State) -> Result<Self>;
    fn run(self, recv: Receiver<WorkerRpc<Self::State>>) -> Result<()>;
}
Expand description

Trait implemented by workers.

Required Associated Constants§

Source

const ID: WorkerId<Self::Parameters>

String identifying the Worker. Used when launching workers in separate processes to specify which workers are supported and which worker to launch. IDs must be unique within a given worker host.

Required Associated Types§

Source

type Parameters: 'static + Send

Parameters passed to launch the worker. Used with Worker::new.

For this worker to be spawned on a remote node, Parameters must implement MeshPayload.

Source

type State: 'static + MeshPayload + Send

State used to implement hot restart. Used with Worker::restart.

Required Methods§

Source

fn new(parameters: Self::Parameters) -> Result<Self>

Instantiates the worker.

The worker should not start running yet, but it can allocate any resources necessary to run.

Source

fn restart(state: Self::State) -> Result<Self>

Restarts a worker from a previous worker’s execution state.

Source

fn run(self, recv: Receiver<WorkerRpc<Self::State>>) -> Result<()>

Synchronously runs the worker on the current thread.

The worker should respond to commands sent in recv. If recv is closed, the worker should exit.

The worker ends when it returns from this function.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§