Skip to main content

Crate dactor_coerce

Crate dactor_coerce 

Source
Expand description

§dactor-coerce

Coerce adapter for the dactor distributed actor framework (v0.2 API).

This crate provides CoerceRuntime, which spawns dactor actors as real coerce-rs actors. Messages are delivered through coerce’s mailbox as type-erased dispatch envelopes, supporting multiple Handler<M> impls per actor.

§Quick start

use dactor::prelude::*;
use dactor::message::Message;
use dactor_coerce::CoerceRuntime;
use async_trait::async_trait;

struct MyActor;

impl Actor for MyActor {
    type Args = ();
    type Deps = ();
    fn create(_: (), _: ()) -> Self { MyActor }
}

struct Greet(String);
impl Message for Greet { type Reply = (); }

#[async_trait]
impl Handler<Greet> for MyActor {
    async fn handle(&mut self, msg: Greet, _ctx: &mut ActorContext) {
        println!("Got: {}", msg.0);
    }
}

#[tokio::main]
async fn main() {
    let runtime = CoerceRuntime::new();
    let actor = runtime.spawn::<MyActor>("greeter", ()).await.unwrap();
    actor.tell(Greet("hello".into())).unwrap();
}

Re-exports§

pub use cluster::CoerceClusterEvents;
pub use runtime::CoerceActorRef;
pub use runtime::CoerceRuntime;
pub use runtime::CoerceSystemActorRefs;
pub use runtime::SpawnOptions;
pub use system_actors::CancelManagerActor;
pub use system_actors::NodeDirectoryActor;
pub use system_actors::SpawnManagerActor;
pub use system_actors::WatchManagerActor;
pub use dactor;

Modules§

cluster
runtime
V0.2 coerce adapter runtime for the dactor actor framework.
system_actors
Native coerce actor implementations for dactor system actors.