[][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, Receive, 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 Receive<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();

Re-exports

pub use services::handle::Notify;
pub use services::handle::Serve;
pub use services::service::Service;

Modules

services

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 in the Receive trait 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.

Receive

This Trait allow Actors to receive messages.

Respond

This Trait allow Actors to receive messages and, additionally, respond to them.