compio_actor/actor/
mod.rs1mod deliver;
4mod handle;
5
6pub(crate) use deliver::{Delivering, finish, run};
7#[doc(inline)]
8pub use handle::{ActorExit, ActorHandle, ActorHandleError};
9
10use crate::Mailbox;
11
12pub trait Message: Send + 'static {}
14
15impl<T: Send + 'static> Message for T {}
16
17#[allow(async_fn_in_trait)]
19pub trait Actor: Sized + 'static {
20 type State: 'static;
22 type Arguments: Send + 'static;
24 type Error: Send + 'static;
26
27 async fn pre_start(
29 &self,
30 myself: &Mailbox<Self>,
31 arguments: Self::Arguments,
32 ) -> Result<Self::State, Self::Error>;
33
34 async fn post_start(
36 &self,
37 _myself: &Mailbox<Self>,
38 _state: &mut Self::State,
39 ) -> Result<(), Self::Error> {
40 Ok(())
41 }
42
43 async fn pre_stop(
45 &self,
46 _myself: &Mailbox<Self>,
47 _state: &mut Self::State,
48 ) -> Result<(), Self::Error> {
49 Ok(())
50 }
51
52 async fn post_stop(
54 &self,
55 _myself: &Mailbox<Self>,
56 _state: &mut Self::State,
57 ) -> Result<(), Self::Error> {
58 Ok(())
59 }
60}
61
62#[allow(async_fn_in_trait)]
64pub trait Handler<M: Message>: Actor {
65 async fn handle(
67 &self,
68 myself: &Mailbox<Self>,
69 message: M,
70 state: &mut Self::State,
71 ) -> Result<(), Self::Error>;
72}