use std::marker::PhantomData;
use acktor::{Actor, Address, BoxError, JoinHandle, Recipient};
use super::RemoteActor;
use crate::remote_message::RemoteMessage;
pub trait RemoteActorFactory: RemoteActor {
const TYPE_NAME: &'static str;
fn create_remote(
label: String,
config: String,
) -> Result<(Address<Self>, JoinHandle<()>), <Self as Actor>::Error>;
}
pub(crate) trait DynRemoteActorFactory: Send + Sync + 'static {
fn create_remote(
&self,
label: String,
config: String,
) -> Result<(Recipient<RemoteMessage>, JoinHandle<()>), BoxError>;
}
pub(crate) struct RemoteActorShim<A>(pub(crate) PhantomData<fn() -> A>);
impl<A> DynRemoteActorFactory for RemoteActorShim<A>
where
A: RemoteActorFactory,
{
fn create_remote(
&self,
label: String,
config: String,
) -> Result<(Recipient<RemoteMessage>, JoinHandle<()>), BoxError> {
let (address, join_handle) = A::create_remote(label, config).map_err(Into::into)?;
Ok((address.into(), join_handle))
}
}