acktor
A pure-Rust actor framework built on top of the Tokio async runtime, inspired by Alice Ryhl's Actors with Tokio.
About
acktor is an actor framework for Rust that builds on the patterns described in Alice Ryhl's blog post and extends them into a structured library. Each actor runs as an independent tokio task with its own mailbox, processing messages one at a time. Actors communicate exclusively through message passing — there is no shared mutable state. The framework provides lifecycle hooks, supervision, an observer pattern, and support for periodic tasks.
Installation
Install acktor by adding it to your Cargo.toml:
[]
= "1.0"
Requires Rust 1.88 or later.
Quick Start
An example Counter actor that handles arithmetic messages might be the following:
use ;
// 1. Define your actor
;
// 2. Define a message
// 3. Implement the handler
async
Supervision
Implement Handler<SupervisionEvent<A>> on the supervisor actor. Use the command Supervisor::Set to attach the supervisor actor to the child (or Supervisor::Unset to detach). Since every actor handles Supervisor<A> automatically, no extra wiring is needed on the child side.
use ;
;
;
Observer
For a subject actor, implement the SubjectActor<Event> trait so it can emit Events to registered observers. Every subject actor automatically gets a Handler<Observer<Event>> implementation that manages the observers, so the observers can be registered by sending Observer::Register commands to the subject actor (or Observer::Unregister to stop receiving events).
use ;
;
Cron Tasks
Use CronContext<Self> as the actor's context and implement CronActor trait to opt in this feature. CronActor trait defines a task method that is invoked repeatedly with a delay determined by its return value.
use Duration;
use ;
;
IPC Support
Actors in different processes can talk to each other through the acktor-ipc crate. Enable the ipc feature on acktor, add acktor-ipc to your dependencies, mark the actors you want to expose with #[derive(RemoteAddressable)] + #[remote], and connect them through a Node over a pipe or websocket transport. See the acktor-ipc README and the pingpong example for a full walkthrough.
Feature Flags
Defaults: derive, observer, cron.
| Feature | Purpose |
|---|---|
derive |
Re-exports the derive macros from acktor-derive. |
observer |
Enables the observer module. |
cron |
Enables the cron module. |
identifier |
Enables stable type identifiers. |
ipc |
Enables IPC support (codec module, remote addressing). |
prost-codec |
Use an all-prost primitive codec instead of the zerocopy mix. |
bottleneck-warning |
Logs when an observer's mailbox is full. |
tokio-tracing |
Names actor tasks for tokio-console (needs tokio_unstable). |
License
This project is licensed under MIT.