Skip to main content

Actor

Trait Actor 

Source
pub trait Actor: Sized + 'static {
    type State: 'static;
    type Arguments: Send + 'static;
    type Error: Send + 'static;

    // Required method
    async fn pre_start(
        &self,
        myself: &Mailbox<Self>,
        arguments: Self::Arguments,
    ) -> Result<Self::State, Self::Error>;

    // Provided methods
    async fn post_start(
        &self,
        _myself: &Mailbox<Self>,
        _state: &mut Self::State,
    ) -> Result<(), Self::Error> { ... }
    async fn pre_stop(
        &self,
        _myself: &Mailbox<Self>,
        _state: &mut Self::State,
    ) -> Result<(), Self::Error> { ... }
    async fn post_stop(
        &self,
        _myself: &Mailbox<Self>,
        _state: &mut Self::State,
    ) -> Result<(), Self::Error> { ... }
}
Available on crate feature actor only.
Expand description

A single-threaded actor with serial access to its state.

Required Associated Types§

Source

type State: 'static

State owned by the actor task.

Source

type Arguments: Send + 'static

Values moved to the worker to initialize the actor.

Source

type Error: Send + 'static

Errors reported across the cluster.

Required Methods§

Source

async fn pre_start( &self, myself: &Mailbox<Self>, arguments: Self::Arguments, ) -> Result<Self::State, Self::Error>

Initializes state on the actor’s worker.

Provided Methods§

Source

async fn post_start( &self, _myself: &Mailbox<Self>, _state: &mut Self::State, ) -> Result<(), Self::Error>

Runs inside the actor task before it receives messages.

Source

async fn pre_stop( &self, _myself: &Mailbox<Self>, _state: &mut Self::State, ) -> Result<(), Self::Error>

Runs after message processing ends but before the mailbox is dropped.

Source

async fn post_stop( &self, _myself: &Mailbox<Self>, _state: &mut Self::State, ) -> Result<(), Self::Error>

Runs after the mailbox has closed.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§