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§
Sourceconst ID: WorkerId<Self::Parameters>
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§
Sourcetype Parameters: 'static + Send
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
.
Sourcetype State: 'static + MeshPayload + Send
type State: 'static + MeshPayload + Send
State used to implement hot restart. Used with Worker::restart
.
Required Methods§
Sourcefn new(parameters: Self::Parameters) -> Result<Self>
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.
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.