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 behaviorLink: Strong reference to an actor for sending messagesEnvelope: Type-safe message containers for request-response patternsHandler: Trait for polymorphic message handlingMulti: 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§
Structs§
- Actor
Context - Runtime context for an active actor instance.
- Call
- Drop
Handle - DynLink
- Envelope
- Exec
- Init
- Initialization context provided to actors during startup.
- Link
- Mpsc
Channel - Multi
- NoReply
- Proxy
- Weak
Link
Enums§
Traits§
Functions§
- spawn
- Spawn a new actor instance with the given specification.