Skip to main content

Actor

Trait Actor 

Source
pub trait Actor:
    Sized
    + Send
    + 'static {
    type Msg: Send + 'static;

    // Required method
    fn handle<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        ctx: &'life1 mut Context<Self>,
        msg: Self::Msg,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn pre_start<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn post_stop<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn pre_restart<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
        _err: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn post_restart<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
        _err: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_terminated<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
        _path: &'life2 ActorPath,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn on_directive<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _ctx: &'life1 mut Context<Self>,
        _directive: &'life2 Directive,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn supervisor_strategy(&self) -> SupervisorStrategy { ... }
}
Expand description

The user-facing Actor trait.

is expressed here as: each actor has an associated Msg type (typically an enum) and implements an async handle that matches on it.

Required Associated Types§

Source

type Msg: Send + 'static

Required Methods§

Source

fn handle<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 mut Context<Self>, msg: Self::Msg, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Process a single message.

Provided Methods§

Source

fn pre_start<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called once before the first message.

Source

fn post_stop<'life0, 'life1, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called after the actor has been stopped.

Source

fn pre_restart<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, _err: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when the actor is about to be restarted by the supervisor.

Source

fn post_restart<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, _err: &'life2 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called after a restart.

Source

fn on_terminated<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, _path: &'life2 ActorPath, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when a watched actor terminates. The path argument is the path of the actor that just stopped. Default is a no-op. Implementations may translate this into a user-visible message (the Python binding does this for Terminated events).

Source

fn on_directive<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _ctx: &'life1 mut Context<Self>, _directive: &'life2 Directive, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Called when the supervisor pushes a graded operating-mode change (Directive::Throttle, Directive::Suspend, or Directive::ResumeFrom) into this still-running actor — no restart, state preserved (FR-6). The actor is expected to gate its own outbound effects (order rate/size, flat-only, etc.) accordingly. Default no-op.

The crash-recovery directives (Resume/Restart/Stop/Escalate) do not invoke this hook — they keep their existing lifecycle semantics.

Source

fn supervisor_strategy(&self) -> SupervisorStrategy

The supervisor strategy this actor applies to its own children.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§