Crate simpl_actor

source ·
Expand description

simpl_actor - A Rust library for actor-based concurrency, built on Tokio.

§Features

  • Simple Actor Definition: Define actors with minimal code using Rust structs and macros.
  • Automatic Message Handling: Leverages Rust’s type system and async capabilities.
  • Asynchronous & Synchronous Messaging: Flexible interaction patterns for actors.
  • Lifecycle Management: Hooks for actor initialization, restart, and shutdown.

§Quick Start

use simpl_actor::{actor, Actor, Spawn};

#[derive(Actor, Default)]
pub struct CounterActor { count: i64 }

#[actor]
impl CounterActor {
    #[message]
    pub fn inc(&mut self, amount: i64) { ... }

    #[message]
    pub fn count(&self) -> i64 { ... }

    #[message]
    pub async fn fetch(&self) -> String { ... }
}

let actor = CounterActor::default().spawn();
actor.inc(1).await?;
actor.count().await?; // Returns 1
actor.fetch().await?;

§Messaging Variants

Provides six variants for message handling, ranging from synchronous to non-blocking asynchronous methods, with or without timeouts.

Enums§

  • Error that can occur when sending a message to an actor.
  • Reason for an actor being stopped.
  • Enum indiciating if an actor should be restarted or not after panicking.
  • Enum indiciating if an actor should be stopped.

Traits§

  • Defines the core functionality for actors within an actor-based concurrency model.
  • Provides functionality to stop and wait for an actor to complete based on an actor ref.
  • Provides functionality to spawn actors and obtain references to them.

Attribute Macros§

  • Attribute macro placed on impl blocks of actors to defined messages.

Derive Macros§

  • Derive macro implementing the Actor trait with default behaviour.