Crate actor12

Crate actor12 

Source
Expand description

§Actor12 Framework

A lightweight, type-safe actor framework for Rust built on async/await.

§Overview

Actor12 provides a simple yet powerful actor model implementation that leverages Rust’s type system and async capabilities. Actors are isolated units of computation that communicate through message passing, ensuring thread safety and preventing data races.

§Key Features

  • Type Safety: Compile-time guarantees for message types and actor interactions
  • Async/Await: Built on Tokio for high-performance async execution
  • Flexible Messaging: Multiple patterns for different use cases
  • Hierarchical Cancellation: Clean shutdown and resource management
  • Zero-Cost Abstractions: Minimal runtime overhead

§Quick Start

use actor12::prelude::*;
use actor12::{spawn, Envelope, Multi, MpscChannel};

// Define your actor
struct Counter {
    count: i32,
}

impl Actor for Counter {
    type Message = Multi<Self>;
    type Spec = ();
    type Channel = MpscChannel<Self::Message>;
    type Cancel = ();
    type State = ();

    fn state(_spec: &Self::Spec) -> Self::State {
        ()
    }

    fn init(_ctx: Init<'_, Self>) -> impl std::future::Future<Output = Result<Self, Self::Cancel>> + Send + 'static {
        std::future::ready(Ok(Counter { count: 0 }))
    }
}

// Spawn the actor
let link = spawn::<Counter>(());

§Architecture

The framework is built around several core concepts:

  • Actor: The core trait defining actor behavior
  • Link: Strong reference to an actor for sending messages
  • Envelope: Type-safe message containers for request-response patterns
  • Handler: Trait for polymorphic message handling
  • Multi: Support for handling multiple message types in a single actor

§Examples

See the examples/ directory for comprehensive usage patterns including:

  • Basic request-response communication
  • State management
  • Multiple message types
  • Error handling
  • Worker pools

Modules§

cancel
count
prelude
Common imports for working with the Actor12 framework.

Structs§

ActorContext
Runtime context for an active actor instance.
Call
DropHandle
DynLink
Envelope
Exec
Init
Initialization context provided to actors during startup.
Link
MpscChannel
Multi
NoReply
Proxy
WeakLink

Enums§

ActorError

Traits§

Actor
Handler

Functions§

spawn
Spawn a new actor instance with the given specification.