Trait tuig::Agent

source ·
pub trait Agent<M: Message>: Send + Sync {
    // Provided methods
    fn start(&mut self, _replies: &mut Replies<M>) -> ControlFlow { ... }
    fn react(&mut self, _msg: &M, _replies: &mut Replies<M>) -> ControlFlow { ... }
}
Expand description

An agent in the system, which can react to messages of a specific type by spawning more agents or messages.

See the crate root for details.

Provided Methods§

source

fn start(&mut self, _replies: &mut Replies<M>) -> ControlFlow

Called once on (re)start, to queue any starting events/ControlFlow as necessary. This will always be called before react.

By default, does nothing and returns ControlFlow::Continue to allow Self::react to be called, under the assumption that your interesting code sits there.

source

fn react(&mut self, _msg: &M, _replies: &mut Replies<M>) -> ControlFlow

React to the events of a round, indicating when the agent should be called next and optionally queueing some more events.

By default, does nothing and returns ControlFlow::Kill, under the assumption that you’d have implemented react if you wanted your agent to stay alive and do things.

Implementors§