Skip to main content

acktor_ipc/session/
command.rs

1//! Commands which can be used to interact with a session.
2//!
3
4use std::marker::PhantomData;
5
6use acktor::{Actor, Address, Message, actor::RemoteAddressable};
7
8use crate::actor_ref::ActorRef;
9use crate::error::SessionError;
10use crate::remote::RemoteSpawnable;
11
12type Result<T> = std::result::Result<T, SessionError>;
13
14/// A command which is used to create an actor in a remote node.
15///
16/// The actor type should have been registered in the remote node's factory registry. If the
17/// operation is successful, the provided `label` will be used as the actor label of the new actor
18/// created in the remote node.
19#[derive(Debug)]
20pub struct RemoteCreateActor<A>
21where
22    A: Actor + RemoteSpawnable,
23{
24    pub label: String,
25    pub config: Option<String>,
26    _marker: PhantomData<fn(A) -> A>,
27}
28
29impl<A> Message for RemoteCreateActor<A>
30where
31    A: Actor + RemoteSpawnable,
32{
33    type Result = Result<Address<A>>;
34}
35
36impl<A> RemoteCreateActor<A>
37where
38    A: Actor + RemoteSpawnable,
39{
40    /// Constructs a new [`RemoteCreateActor`] command for the actor type `A`.
41    pub fn new<S>(label: S, config: Option<String>) -> Self
42    where
43        S: AsRef<str>,
44    {
45        Self {
46            label: label.as_ref().to_string(),
47            config,
48            _marker: PhantomData,
49        }
50    }
51}
52
53/// A command which is used to get the address of an actor in a remote node.
54#[derive(Debug)]
55pub struct RemoteGetActor<A>
56where
57    A: Actor + RemoteAddressable,
58{
59    pub actor: ActorRef,
60    _marker: PhantomData<fn(A) -> A>,
61}
62
63impl<A> Message for RemoteGetActor<A>
64where
65    A: Actor + RemoteAddressable,
66{
67    type Result = Result<Address<A>>;
68}
69
70impl<A> RemoteGetActor<A>
71where
72    A: Actor + RemoteAddressable,
73{
74    /// Constructs a new [`RemoteGetActor`] command for the actor type `A`.
75    pub fn new(actor: ActorRef) -> Self {
76        Self {
77            actor,
78            _marker: PhantomData,
79        }
80    }
81}