Skip to main content

Crate free_agent

Crate free_agent 

Source
Expand description

Episodes in which actors talk to each other by statement, request, and reply.

The crate-level documentation is the project README, included below so the two stay one document.

§Free Agent

CI codecov

Episodes in which actors talk to each other by statement, request, and reply.

An episode brings a set of actors into being together, decides which of them can reach which, and runs them on the Tokio runtime until every one of them has stopped. An actor is one in the sense of the actor model: it keeps its own state, takes messages from a mailbox one at a time, and reaches other actors only by sending them messages. Here it is a Behavior driven by a mailbox: the behavior handles statements with receive and requests with answer, and its Context is how it reaches the rest of the episode, to send statements, to request and await replies, to stop other actors, and to log. A typical episode has one environment actor and several agent actors.

The library lives at the root of the repository and the applications built on it under apps/. For games built on this, see social-deduction.

§Development

cargo test                                   # unit tests and doctests
cargo doc --no-deps --open                   # the API docs
cargo fmt --check                            # what CI checks, besides the above
cargo clippy --all-targets -- -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
cargo llvm-cov --workspace                   # test coverage, which CI reports to Codecov

Structs§

ActorInit
Everything an Episode needs to build one actor: how it behaves and whom it may reach.
Context
The ways out of an actor: what a Behavior may do besides answer.
Episode
A set of actors brought into being together, wired to one another as their inits allow, and run until every one of them has stopped.
Event
Something an actor wanted written down, stamped with when it said so and which episode it was in. The payload is whatever the episode’s actors log, most often their message type.

Traits§

Behavior
What an actor does at each point in its life. It initializes, makes an opening move once every actor is running, then maps what it receives to what it does: a statement goes to receive and a request to answer, whose result is the reply. On the way out it cleans up. Every method but context has an empty default, so the simplest behavior is a context and nothing else. Anything else the behavior wants to say, such as who it is, goes inside its messages.
Message
What one episode’s actors say to one another.

Functions§

console_log
drain to standard error.
drain
Write every event from events to sink, each as Event::write does, until every logger is gone.

Type Aliases§

ActorId
An actor’s name, unique within an episode.
Builder
Builds a Behavior from the Context it will own.
Logger
The sending end of an episode’s log.