Trait tuig::Message

source ·
pub trait Message: Clone + Send + Sync {
    // Required method
    fn tick() -> Self;
}
Expand description

A message that Agents and Games will be passing around.

The relevant agents and games will be taking this as a generic parameter, not using it as a trait object, and you should do the same. Usually you’ll implement this in an enum. If you want a trait object, use Message as a supertrait for yours.

This trait requires Clone, Send, and Sync, to ensure it can be properly shared across all threads.

Required Methods§

source

fn tick() -> Self

The message to send agents when there aren’t any other messages queued for processing, to ensure every awake agent processes at least one message per round. Will not be sent if there are any other messages!

This method should be as simple and fast as possible, ideally just returning a constant value.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Clone + Send + Sync + Default> Message for T

Primarly so you can use basic integer types as messages in tests like mass-messages, automatically implement Message for Default types. Message::tick() returns Default::default().