Skip to main content

ParallelModel

Trait ParallelModel 

Source
pub trait ParallelModel<E, Command>: Model<E> {
    // Required methods
    fn handle_event_parallel(&self, event: Event<E>, sender: Sender<Command>);
    fn apply_command(
        &mut self,
        context: &mut EventContext<E, Self>,
        command: Command,
    )
       where Self: Sized;
}
Expand description

An extension trait for models supporting parallel execution.

This trait extracts model state changes into commands that are aggregated on the main thread, preventing data races in concurrent environments.

Required Methods§

Source

fn handle_event_parallel(&self, event: Event<E>, sender: Sender<Command>)

An event handler invoked from asynchronous (parallel) threads. Sends a Command representing a state change request through the provided sender.

Source

fn apply_command( &mut self, context: &mut EventContext<E, Self>, command: Command, )
where Self: Sized,

Applies the result of parallel computation (Command) to the model on the main thread.

Since &mut self is provided here, state updates can be performed safely.

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§