[][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, System};
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 = System::new();

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

sys.wait_until_stopped();

Structs

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.

System

The system is external inteface to the actor runtime. It allow to send messages, to stop it, configure it, etc. Once you contructed with the method "new" you can start sending messages. The system will automatically start any required actor automatically and unload them when required.

Traits

Actor

The main Trait from this crate.

Handle

This Trait allow Actors to receive messages.