pub trait Actor: Send + 'static {
type Args: Send + 'static;
type Deps: Send + 'static;
// Required method
fn create(args: Self::Args, deps: Self::Deps) -> Self
where Self: Sized;
// Provided methods
fn on_start<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ctx: &'life1 mut ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn on_error(&mut self, _error: &ActorError) -> ErrorAction { ... }
}Expand description
The core actor trait. Implemented by the user’s actor struct.
State lives in self. Lifecycle hooks have default no-ops.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn on_start<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ctx: &'life1 mut ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_start<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_ctx: &'life1 mut ActorContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Called after spawn, before any messages. Default: no-op. Use for async initialization, resource acquisition, subscriptions.
Sourcefn on_stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_stop<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Called when the actor is stopping. Default: no-op. Use for cleanup, resource release, flushing buffers.
Sourcefn on_error(&mut self, _error: &ActorError) -> ErrorAction
fn on_error(&mut self, _error: &ActorError) -> ErrorAction
Called on handler error/panic. Returns what to do next.