pub trait Worker: Sized + Send + 'static {
    type Init: 'static + Send;
    type Input: 'static + Send + Debug;
    type Output: 'static + Send + Debug;

    // Required methods
    fn init(init: Self::Init, sender: ComponentSender<Self>) -> Self;
    fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>);
}
Expand description

Receives inputs and outputs in the background.

All types that implement Worker will also implement Component automatically.

If you need more flexibility when using workers, you can simply implement Component instead and set the Component::Widgets and Component::Root types both to (). This will still allow you to use all worker related methods because internally a worker is just seen as a Component without widgets.

Required Associated Types§

source

type Init: 'static + Send

The initial parameters that will be used to build the worker state.

source

type Input: 'static + Send + Debug

The type of inputs that this worker shall receive.

source

type Output: 'static + Send + Debug

The type of outputs that this worker shall send.

Required Methods§

source

fn init(init: Self::Init, sender: ComponentSender<Self>) -> Self

Defines the initial state of the worker.

source

fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>)

Defines how inputs will bep processed

Object Safety§

This trait is not object safe.

Implementors§