pub trait Actor:
Send
+ Sync
+ 'static {
type Message: Send + 'static;
type State: Send + 'static;
type Initialize: Send + 'static;
// Required methods
fn initialize<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
handle: &'life1 ActorHandle<Self::Message>,
tags: &'life2 Tags,
initialize: Self::Initialize,
) -> Pin<Box<dyn Future<Output = Result<Self::State, ActorError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
handle: &'life1 ActorHandle<Self::Message>,
message: Self::Message,
state: &'life2 mut Self::State,
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn tags(&self, tags: Tags) -> Result<Tags, ActorError> { ... }
fn shutdown<'life0, 'async_trait>(
&'life0 self,
_state: Self::State,
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn spawner(
tags: Tags,
actor: Self,
) -> Result<ActorSpawner<Self>, ActorError>
where Self: Send + Sync + Sized + 'static { ... }
fn spawn(
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<ActorInstance<Self>, ActorError>
where Self: Send + Sync + Sized + 'static { ... }
fn spawn_with(
spawner: TaskSpawner,
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<ActorInstance<Self>, ActorError>
where Self: Send + Sync + Sized + 'static { ... }
}Expand description
Simple actor model implementation. Accepts messages which will be applied to the actor state. Actor state is different to the actual actor instance in order to allow initialization of it within the actor context.
Required Associated Types§
type Message: Send + 'static
type State: Send + 'static
type Initialize: Send + 'static
Required Methods§
fn initialize<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
handle: &'life1 ActorHandle<Self::Message>,
tags: &'life2 Tags,
initialize: Self::Initialize,
) -> Pin<Box<dyn Future<Output = Result<Self::State, ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
handle: &'life1 ActorHandle<Self::Message>,
message: Self::Message,
state: &'life2 mut Self::State,
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Provided Methods§
Sourcefn shutdown<'life0, 'async_trait>(
&'life0 self,
_state: Self::State,
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
_state: Self::State,
) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Shutdown the actor. This is not cancelable. After this call no more message will be received. Will not be executed if actor panics.
fn spawner(tags: Tags, actor: Self) -> Result<ActorSpawner<Self>, ActorError>
Sourcefn spawn(
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<ActorInstance<Self>, ActorError>
fn spawn( tags: Tags, actor: Self, initialize: Self::Initialize, ) -> Result<ActorInstance<Self>, ActorError>
Spawn actor.
Sourcefn spawn_with(
spawner: TaskSpawner,
tags: Tags,
actor: Self,
initialize: Self::Initialize,
) -> Result<ActorInstance<Self>, ActorError>
fn spawn_with( spawner: TaskSpawner, tags: Tags, actor: Self, initialize: Self::Initialize, ) -> Result<ActorInstance<Self>, ActorError>
Spawn actor using a task spawner.