use crate::ctx::ActorContext;
use crate::mailbox::MailboxPolicy;
use crate::msg::{ActorMsg, ActorSignal};
use std::future::Future;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActorAction {
Continue,
Stop,
}
pub trait Actor: Sized + Send + 'static {
type Message: ActorMsg;
const POLICY: MailboxPolicy = MailboxPolicy::DEFAULT;
fn mailbox_policy() -> MailboxPolicy {
Self::POLICY
}
fn handle(
&mut self,
msg: Self::Message,
ctx: &mut ActorContext<Self::Message>,
) -> impl Future<Output = ActorAction> + Send;
fn on_restart(
&mut self,
_attempt: u32,
_ctx: &mut ActorContext<Self::Message>,
) -> impl Future<Output = ()> + Send {
async {}
}
fn on_start(&mut self, _ctx: &mut ActorContext<Self::Message>) -> impl Future<Output = ()> + Send {
async {}
}
fn on_stop(&mut self, _ctx: &mut ActorContext<Self::Message>) -> impl Future<Output = ()> + Send {
async {}
}
fn on_signal(
&mut self,
_sig: ActorSignal,
_ctx: &mut ActorContext<Self::Message>,
) -> impl Future<Output = ActorAction> + Send {
async { ActorAction::Continue }
}
}