[][src]Crate act_zero


An actor system for Rust, designed with several goals in mind:

  • No boilerplate.
  • Ergonomic.
  • Supports standard trait-based static and dynamic polymorphism.
  • Embraces async/await.
  • Executor agnostic.

There are also some basic building blocks to support remoting, but the actual mechanism to transfer messages is left to the user.

Very little code is required to get started:

use std::error::Error;

use futures::executor::LocalPool;
use act_zero::*;

struct SimpleGreeter {
    number_of_greets: i32,

impl Actor for SimpleGreeter {
    type Error = ();

trait Greeter {
    fn greet(&self, name: String, res: Sender<String>);

impl Greeter for SimpleGreeter {
    async fn greet(&mut self, name: String, res: Sender<String>) {
        self.number_of_greets += 1;
            "Hello, {}. You are number {}!",
            name, self.number_of_greets

fn main() -> Result<(), Box<dyn Error>> {
    let mut pool = LocalPool::new();
    let spawner = pool.spawner();
    pool.run_until(async move {
        let actor_ref = spawn(
            SimpleGreeter {
                number_of_greets: 0,

        let greeting = actor_ref.call_greet("John".into()).await?;
        println!("{}", greeting);

        let greeting = actor_ref.call_greet("Emma".into()).await?;
        println!("{}", greeting);

See #[act_zero] for documentation on the attribute which powers this crate.



This module contains tools for dealing with async functions. These are similar to the FnOnce trait from std, but they allow the lifetime of the returned future to be bound by the lifetime of the argument. The different variants correspond to the different reference types (&T, &mut T) but all variants consume self like FnOnce.


Tools for creating actor proxies. These can be used to communicate with actors in a different process, or on a different machine.


Utility types and traits. These are typically used internally or by macro expansions and you will not normally need to use them directly.



Strong reference to an actor. This will not prevent the actor from stopping of its own volition, but the actor will not be automatically stopped as long as a strong reference still exists. If the actor has stopped, messages sent to the actor will be dropped.


Type of an actor running locally.


A future for a value that will be provided by another asynchronous task.


A means of transmitting a single value to another task.


Weak reference to an actor. If the actor has been dropped, messages sent to the actor will also be dropped.



Implement this trait for types representing actors. The only requirement is that you specify an Error type, all other methods are optional.


This type is automatically implemented for local actors which implement the actor trait corresponding to the message type M.



Creates a new one-shot channel for sending values across asynchronous tasks.


Spawn an actor the provided spawner, returning its address or an error.

Attribute Macros


The #[act_zero] macro.