pub trait Actor: Sized + Send + 'static {
type Args: Send;
type Error: ReplyError;
#[inline]
fn name() -> &'static str {
any::type_name::<Self>()
}
#[allow(unused_variables)]
fn on_start(
args: Self::Args,
actor_ref: ActorRef<Self>,
) -> impl Future<Output = Result<Self, Self::Error>> + Send;
fn on_message(
&mut self,
msg: BoxMessage<Self>,
actor_ref: ActorRef<Self>,
tx: Option<BoxReplySender>,
stop: &mut bool,
) -> impl Future<Output = Result<(), Box<dyn ReplyError>>> + Send {
async move { msg.handle_dyn(self, actor_ref, tx, stop).await }
}
#[allow(unused_variables)]
#[inline]
fn on_panic(
&mut self,
actor_ref: WeakActorRef<Self>,
err: PanicError,
) -> impl Future<Output = Result<ControlFlow<ActorStopReason>, Self::Error>> + Send {
async move { Ok(ControlFlow::Break(ActorStopReason::Panicked(err))) }
}
#[allow(unused_variables)]
#[inline]
fn on_link_died(
&mut self,
actor_ref: WeakActorRef<Self>,
id: ActorId,
reason: ActorStopReason,
) -> impl Future<Output = Result<ControlFlow<ActorStopReason>, Self::Error>> + Send {
async move {
match &reason {
ActorStopReason::Normal => Ok(ControlFlow::Continue(())),
ActorStopReason::Killed
| ActorStopReason::Panicked(_)
| ActorStopReason::LinkDied { .. } => {
Ok(ControlFlow::Break(ActorStopReason::LinkDied {
id,
reason: Box::new(reason),
}))
}
#[cfg(feature = "remote")]
ActorStopReason::PeerDisconnected => {
Ok(ControlFlow::Break(ActorStopReason::PeerDisconnected))
}
}
}
}
#[allow(unused_variables)]
#[inline]
fn on_stop(
&mut self,
actor_ref: WeakActorRef<Self>,
reason: ActorStopReason,
) -> impl Future<Output = Result<(), Self::Error>> + Send {
async { Ok(()) }
}
#[allow(unused_variables)]
#[inline]
fn next(
&mut self,
actor_ref: WeakActorRef<Self>,
mailbox_rx: &mut MailboxReceiver<Self>,
) -> impl Future<Output = Option<Signal<Self>>> + Send {
mailbox_rx.recv()
}
}