Crate cineyma

Crate cineyma 

Source
Expand description

§cineyma

A lightweight, production-focused actor framework for Rust.

cineyma provides typed actors with bounded mailboxes, OTP-style supervision, and distributed messaging over TCP with Protocol Buffers.

§Quick Start

use cineyma::{Actor, Handler, Message, ActorSystem, Context};

// Define a message
struct Greet(String);
impl Message for Greet {
    type Result = String;
}

// Define an actor
struct Greeter;
impl Actor for Greeter {}

impl Handler<Greet> for Greeter {
    fn handle(&mut self, msg: Greet, _ctx: &mut Context<Self>) -> String {
        format!("Hello, {}!", msg.0)
    }
}

#[tokio::main]
async fn main() {
    let system = ActorSystem::new();
    let addr = system.spawn(Greeter);

    // Request-response
    let response = addr.send(Greet("cineyma".into())).await.unwrap();
    assert_eq!(response, "Hello, cineyma!");
}

§Core Concepts

ConceptDescription
ActorTrait for stateful message processors
MessageTrait for typed messages with associated result
Handler<M>Sync message handler implementation
Addr<A>Handle to send messages to an actor
Context<A>Actor’s runtime environment
ActorSystemTop-level runtime that spawns actors

§Sending Messages

// Request-response (awaits result)
let result = addr.send(MyMessage).await?;

// Fire-and-forget with backpressure
addr.do_send(MyMessage).await?;

// Non-blocking (returns MailboxFull if full)
addr.try_send(MyMessage)?;

§Bounded Mailboxes

All actors have bounded mailboxes (default: 256 messages) to prevent OOM:

// Default capacity
let addr = system.spawn(MyActor);

// Custom capacity
let addr = system.spawn_with_capacity(MyActor, 10000);

§Supervision

Actors can supervise children with restart policies:

use cineyma::SupervisorStrategy;
use std::time::Duration;

// Restart up to 3 times within 10 seconds
ctx.spawn_child_with_strategy(
    || MyChild,
    SupervisorStrategy::restart(3, Duration::from_secs(10)),
);

§Modules

ModuleDescription
actorActor and Handler traits
addressActor addressing and message sending
contextRuntime context with child spawning, timers, streams
systemActorSystem for top-level actor management
supervisorSupervision strategies (Stop, Restart, Escalate)
registryNamed actor lookup with auto-cleanup
streamExternal stream integration
remoteTCP transport, clustering, and distributed actors
errorError types (MailboxError)

Re-exports§

pub use actor::Actor;
pub use actor::Handler;
pub use actor::StreamHandler;
pub use address::Addr;
pub use context::Context;
pub use error::MailboxError;
pub use message::Message;
pub use supervisor::SupervisorStrategy;
pub use system::ActorSystem;
pub use timer::TimerHandle;

Modules§

actor
address
context
envelope
error
message
registry
remote
stream
supervisor
system
timer
watcher