acktor_ipc/remote_actor.rs
1//! Traits for actors which can be reached over IPC and a registry of this kind of actors.
2//!
3
4use std::sync::Arc;
5
6use acktor::{Actor, Handler};
7use ahash::HashMap;
8
9use crate::remote_message::RemoteMessage;
10
11mod registry;
12pub use registry::RemoteActorRegistry;
13
14mod factory;
15pub use factory::RemoteActorFactory;
16pub(crate) use factory::{DynRemoteActorFactory, RemoteActorShim};
17
18pub(crate) type RemoteActorFactoryRegistry = HashMap<String, Arc<dyn DynRemoteActorFactory>>;
19
20/// A marker trait for actors which can be reached over IPC.
21///
22/// To make an actor reachable over IPC, the user should implement the [`Handler<RemoteMessage>`]
23/// trait for an actor to define how it processes inbound remote messages, and then register the
24/// actor's address in the [`Node`][crate::Node]'s [`RemoteActorRegistry`] via the
25/// [`with_actor`][crate::Node::with_actor] method or the
26/// [`AddActor`][crate::node::command::AddActor] command.
27///
28/// It is highly recommended to use the [`#[acktor_ipc::remote]`][crate::remote] attribute macro
29/// to annotate the `impl Actor for MyActor { ... }` block of a remote actor. The macro overrides
30/// the [`Actor::type_erased_recipient_fn`] hook, which will opt-in the
31/// `type-erased-recipient-hook` feature, and allow conversion from any `Reciepient` type of this
32/// actor to a `Recipient<RemoteMessage>`. With the help of this hook, the actor's address can be
33/// registered in the [`Node`][crate::Node]'s [`RemoteActorRegistry`] automatically. This is more
34/// convenient than registering the actor manually.
35pub trait RemoteActor: Actor + Handler<RemoteMessage> {}