[][src]Crate acteur

Acteur Actor System

An actor system written in Rust that just works. Simple, robust, fast, documented.

Overall features of Acteur

Example

use acteur::{Actor, Handle, Assistant, Acteur};
use async_trait::async_trait;

#[derive(Debug)]
struct Employee {
    salary: u32
}

#[async_trait]
impl Actor for Employee {
    type Id = u32;

    async fn activate(_: Self::Id) -> Self {
        Employee {
            salary: 0 // Load from DB or set a default,
        }
    }
}

#[derive(Debug)]
struct SalaryChanged(u32);

#[async_trait]
impl Handle<SalaryChanged> for Employee {
    async fn handle(&mut self, message: SalaryChanged, _: &Assistant<Employee>) {
        self.salary = message.0;
    }
}

let sys = Acteur::new();

sys.send_sync::<Employee, SalaryChanged>(42, SalaryChanged(55000));

sys.wait_until_stopped();

Structs

Acteur

Acteur is the main inteface to the actor runtime. It allows sending messages, stopping the runtime, set configurations, etc. Once contructed with the method "new" you can start sending messages. The system will automatically start any required actor and unload them when not used.

Assistant

This object is provided to the Handle method for each message that an Actor receives The Actor's assistant allows to send messages and to execute some task over the system.

Traits

Actor

The main Trait from this crate.

Handle

This Trait allow Actors to receive messages.