10 releases

0.1.1 May 17, 2021
0.1.0 May 17, 2021
0.0.8 May 1, 2021
0.0.7 Apr 12, 2021
0.0.1 Feb 19, 2021

#240 in Concurrency

Download history 21/week @ 2021-03-31 38/week @ 2021-04-07 16/week @ 2021-04-14 22/week @ 2021-04-21 23/week @ 2021-04-28 1/week @ 2021-05-05 39/week @ 2021-05-12 8/week @ 2021-05-19 2/week @ 2021-05-26 10/week @ 2021-06-09 2/week @ 2021-06-23 10/week @ 2021-07-14

66 downloads per month

MIT/Apache

68KB
1K SLoC

Tyractorsaur (TYped Rust ACTOR "SAUR")

Tyractorsaur is a cross platform Typed Actor System Written in Rust.

Current State

It is NOT production ready. Tyractorsaur is in very early development steps. The current development status can be tracked in the CHANGELOG.md

Documentation

docs.rs or generate your own with cargo doc

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Tyractorsaur is a configurable typed actor framework

An Actor is an object with which you can only interact by sending predefined messages

Furthermore Actors are bound to a thread pool and can be moved between executions to any of the threads of said pool.

crossbeam-channel is used for all internal-messaging

Examples

Basic usage:

use tyractorsaur::prelude::*;
use std::process::exit;
use std::time::Duration;

// define message
struct FooBar {}
impl ActorMessage for FooBar {}

// define actor
struct HelloWorld {}
impl Actor for HelloWorld {}

// setup required Factory
struct HelloWorldFactory {}
impl ActorFactory<HelloWorld> for HelloWorldFactory {
    fn new_actor(&self, _context: ActorContext<HelloWorld>) -> HelloWorld {
        HelloWorld {}
    }
}

// each supported message has its own Handler implementation
// this is where the actual work is done
impl Handler<FooBar> for HelloWorld {
    fn handle(&mut self, _msg: FooBar, _context: &ActorContext<Self>) {
        println!("Message Received!");
    }
}

fn main() {
    // create a new actor system with the default config
    let actor_config = TyractorsaurConfig::new().unwrap();
    let actor_system = ActorSystem::new(actor_config);

    // create an actor and send it a message
    let factory = HelloWorldFactory {};
    let actor = actor_system
        .builder()
        .spawn("hello-world", factory)
        .unwrap();
    actor.send(FooBar {});

    // cleanup
    actor.stop();
    actor_system.stop(Duration::from_secs(5));
    exit(actor_system.await_shutdown());
}

Architecture

User POV

                            ┌──────────────────────┐
                            │                      │
                            │  TyractorsaurConfig  │
                            │                      │
                            └──────────┬───────────┘
                                       │
                               ┌───────▼───────┐
                               │               │
              ┌────────────────┤  ActorSystem  ├─────────────────┐
              │                │               │                 │
              │                └───────┬───────┘                 │
              │                        │                         │
     ┌────────▼─────────┐     ┌────────▼─────────┐     ┌─────────▼────────┐
     │                  │     │                  │     │                  │
     │  ActorBuilder A  │     │  ActorBuilder B  │     │  ActorBuilder N  │
     │                  │     │                  │     │                  │
     └┬─────────────────┘     └┬─────────────────┘     └┬─────────────────┘
      │                        │                        │
      │ ┌────────────┐         │  ┌────────────┐        │  ┌────────────┐
      │ │            │         │  │            │        │  │            │
      ├─►  Actor A1  │         ├──►  Actor B1  │        ├──►  Actor N1  │
      │ │            │         │  │            │        │  │            │
      │ └────────────┘         │  └────────────┘        │  └────────────┘
      │                        │                        │
      │ ┌────────────┐         │  ┌────────────┐        │  ┌────────────┐
      │ │            │         │  │            │        │  │            │
      ├─►  Actor A2  │         ├──►  Actor B2  │        ├──►  Actor N2  │
      │ │            │         │  │            │        │  │            │
      │ └────────────┘         │  └────────────┘        │  └────────────┘
      │                        │                        │
      │ ┌────────────┐         │  ┌────────────┐        │  ┌────────────┐
      │ │            │         │  │            │        │  │            │
      └─►  Actor An  │         └──►  Actor Bn  │        └──►  Actor Nn  │
        │            │            │            │           │            │
        └────────────┘            └────────────┘           └────────────┘

Dependencies

~5.5MB
~100K SLoC