pub struct Replies<M: Message> { /* private fields */ }
Expand description
Implementations§
source§impl<M: Message> Replies<M>
impl<M: Message> Replies<M>
sourcepub fn spawn(&mut self, agent: impl Agent<M> + 'static) -> &mut Self
pub fn spawn(&mut self, agent: impl Agent<M> + 'static) -> &mut Self
Have an agent spawned into the next round of messages or so.
tuig will try to spawn the agent in to the immediately next round, but that’s not always guaranteed, and in
particular if the game is lagging it may be some time before new agents are spawned. If you need to ensure
something happens when the agent starts, implement Agent::start
. If one agent needs to synchronize with
one it spawned, have the spawned agent send a “hello” message when it starts.
sourcepub fn spawn_boxed(&mut self, agent: Box<dyn Agent<M>>) -> &mut Self
pub fn spawn_boxed(&mut self, agent: Box<dyn Agent<M>>) -> &mut Self
The same as Replies::spawn
, but with a boxed agent.
Generally, you should use spawn
; it reduces boilerplate. But if you happen to be passing around trait
objects in Boxes anyway, then you should use this.
sourcepub fn queue(&mut self, msg: M) -> &mut Self
pub fn queue(&mut self, msg: M) -> &mut Self
Queues up a message to be sent out in the next round.
Queued messages are guaranteed to be processed in the next round after this one. So:
- Other running agents won’t see this message until next round
- Agents
Self::spawn
ed this round might not see it (see that method for why)
sourcepub fn queue_all(&mut self, msgs: impl IntoIterator<Item = M>) -> &mut Self
pub fn queue_all(&mut self, msgs: impl IntoIterator<Item = M>) -> &mut Self
Self::queue
s up several messages to be sent out in the next round.
source§impl<M: Message> Replies<M>
impl<M: Message> Replies<M>
Some test-only functionality letting you introspect Replies
, to test that Agent
s or Game
s are reacting
properly to things that happen.
sourcepub fn _messages(&self) -> &[M]
pub fn _messages(&self) -> &[M]
A test-only function, listing the messages that have been Self::queue
d.
sourcepub fn _agents(&self) -> &[Box<dyn Agent<M>>]
pub fn _agents(&self) -> &[Box<dyn Agent<M>>]
A test-only function, listing the agents that have been Self::spawn
ed.
Trait Implementations§
Auto Trait Implementations§
impl<M> !RefUnwindSafe for Replies<M>
impl<M> Send for Replies<M>
impl<M> Sync for Replies<M>
impl<M> Unpin for Replies<M>where M: Unpin,
impl<M> !UnwindSafe for Replies<M>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.