pub trait Participant: Sized {
type Message;
// Required methods
fn id(&self) -> AgentId;
fn bundle(&self) -> &Bundle<TaskId>;
fn act(&mut self, now: u64, outbox: &mut Vec<Self::Message>);
fn receive(
&mut self,
now: u64,
message: &Self::Message,
outbox: &mut Vec<Self::Message>,
) -> bool;
fn message_bytes(message: &Self::Message) -> u64;
fn is_settled(team: &[Self], in_flight: &[&Self::Message]) -> bool;
}Expand description
An agent that a Simulation can run: it works in rounds, broadcasts messages, and
handles the messages that reach it.
cbba::Agent implements it; so can other consensus protocols.
Required Associated Types§
Required Methods§
Sourcefn act(&mut self, now: u64, outbox: &mut Vec<Self::Message>)
fn act(&mut self, now: u64, outbox: &mut Vec<Self::Message>)
One round of the agent’s own work at tick now, such as its bundle phase; pushes
what it broadcasts onto outbox.
Sourcefn receive(
&mut self,
now: u64,
message: &Self::Message,
outbox: &mut Vec<Self::Message>,
) -> bool
fn receive( &mut self, now: u64, message: &Self::Message, outbox: &mut Vec<Self::Message>, ) -> bool
Handles message, arriving at tick now; pushes what the agent broadcasts in
response onto outbox. Returns whether the agent’s winners, bids or bundle changed,
for Stats::useful.
Sourcefn message_bytes(message: &Self::Message) -> u64
fn message_bytes(message: &Self::Message) -> u64
The size of message on the wire, in bytes, for Stats::bytes.
The protocols in this crate use a nominal encoding without compression: 4 bytes per agent or task identifier (an absent winner takes a reserved value), 8 per bid, timestamp or clock, 1 per tag, and a 4-byte length before every list.
Sourcefn is_settled(team: &[Self], in_flight: &[&Self::Message]) -> bool
fn is_settled(team: &[Self], in_flight: &[&Self::Message]) -> bool
Whether team has settled, with in_flight still on its way: the agents agree on a
conflict-free assignment that nothing in flight and no further round can change.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".