Trait Communicator
pub trait Communicator<I, T>: Sized {
// Required methods
fn send(&mut self, receiver: &I, message: T) -> Result<(), SimulationError>;
fn receive(&mut self) -> Vec<T>;
}
chili
only.Expand description
Handles communications between different simulation processes.
Often times, information needs to be exchanged between threads. For example, positional and force information of cells living at the boundary.
The receiver is referenced by the index I
and will obtain the message T
.
The trait was designed around the [crossbeam_channel] sender-receiver pair.
However, it should allow for more generic setups where eg. information could be shared
by different means such as sharing memory.
Between the Communicator::send and Communicator::receive method, a synchronization step needs to happen. Otherwise, dataraces can occur and invalidate given results. See the Sync trait for more details on syncing between threads.
Required Methods§
fn send(&mut self, receiver: &I, message: T) -> Result<(), SimulationError>
fn send(&mut self, receiver: &I, message: T) -> Result<(), SimulationError>
Sends information to a particular receiver.
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.