Skip to main content

Actor

Trait Actor 

Source
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§

Source

type Args: Send + 'static

Serializable construction arguments for creating this actor.

Source

type Deps: Send + 'static

Non-serializable local dependencies, resolved at the target node.

Required Methods§

Source

fn create(args: Self::Args, deps: Self::Deps) -> Self
where Self: Sized,

Construct the actor from serializable args and local deps.

Called by the runtime during spawn. Perform only synchronous initialization here; use on_start for async setup.

Provided Methods§

Source

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.

Source

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.

Source

fn on_error(&mut self, _error: &ActorError) -> ErrorAction

Called on handler error/panic. Returns what to do next.

Implementors§