Crate xtor

source · []
Expand description

Xtor: An handler async actor framework.


Key features

  • small: very small codebase
  • async: allow you to write async code in your actor
  • full featured: we have built-in types such as Supervisor Broker Caller and so on
  • both dynamic and fast: typed message and weak typed event.


add xtor to your library

cargo add xtor

write some code

use anyhow::Result;
use async_trait::async_trait;
use xtor::actor::{context::Context, message::Handler, runner::Actor};

// first define actor
struct HelloActor;
impl Actor for HelloActor {}

// then define message
#[xtor::message(result = "()")]
struct Hello;

// then impl the handler
impl Handler<Hello> for HelloActor {
    async fn handle(&self, _ctx: &Context, msg: Hello) -> Result<()> {
        println!("{:?} received", &msg);

// main will finish when all actors died out.
async fn main() -> Result<()> {
    let hello_actor = HelloActor;
    let hello_actor_address = hello_actor.spawn().await?;<HelloActor, Hello>(Hello).await

More Examples?

please take a look at the examples folder in the repository.


pub use actor::*;


the core of xtor

default implemention of broker, supervisor and so on.


exports to the derive macro

exports to the derive macro

Attribute Macros

Xtor main derive

Xtor Message Derive

Xtor test derive