#actor #threads

tonari-actor

A minimalist actor framework aiming for high performance and simplicity

4 releases (2 breaking)

0.5.0 May 12, 2021
0.4.1 Mar 4, 2021
0.4.0 Mar 3, 2021
0.3.0 Mar 1, 2021

#247 in Asynchronous

Download history 6/week @ 2021-04-03 6/week @ 2021-04-10 6/week @ 2021-04-17 45/week @ 2021-04-24 15/week @ 2021-05-01 65/week @ 2021-05-08 27/week @ 2021-05-15 61/week @ 2021-05-22 42/week @ 2021-05-29 27/week @ 2021-06-05 27/week @ 2021-06-12 45/week @ 2021-06-19 49/week @ 2021-06-26 46/week @ 2021-07-03 31/week @ 2021-07-10 59/week @ 2021-07-17

79 downloads per month

MIT license

42KB
821 lines

tonari-actor

Crates.io Documentation

This crate aims to provide a minimalist and high-performance actor framework for Rust with significantly less complexity than other frameworks like Actix.

In this framework, each Actor is its own OS-level thread. This makes debugging noticeably simpler, and is suitably performant when the number of actors is less than or equal to the number of CPU threads.

Example

use tonari_actor::{Actor, Context, System};

struct TestActor {}

impl Actor for TestActor {
    type Error = ();
    type Message = usize;

    fn name() -> &'static str {
        "TestActor"
    }

    fn handle(&mut self, _context: &Context<Self>, message: Self::Message) -> Result<(), ()> {
        println!("message: {}", message);

        Ok(())
    }
}

fn main() {
    let mut system = System::new("default");

    // will spin up a new thread running this actor
    let addr = system.spawn(TestActor {}).unwrap();

    // send messages to actors to spin off work...
    addr.send(1usize).unwrap();

    // ask the actors to finish and join the threads.
    system.shutdown().unwrap();
}

Dependencies

  • cargo
  • rustc

Build

$ cargo build --release

Testing

$ cargo test

Code Format

The formatting options currently use nightly-only options.

$ cargo +nightly fmt

Code Linting

$ cargo clippy

Dependencies

~1MB
~19K SLoC