Trait Actor

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

    // Required method
    fn new<'async_trait>(
        params: Self::Params,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
       where Self: 'async_trait;

    // Provided methods
    fn init<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _this: &'life1 Instance<Self>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn spawn<'life0, 'async_trait>(
        cap: &'life0 (impl 'async_trait + CanSpawn),
        params: Self::Params,
    ) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn spawn_detached<'async_trait>(
        params: Self::Params,
    ) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait { ... }
    fn spawn_server_task<F>(future: F) -> JoinHandle<F::Output>
       where F: Future + Send + 'static,
             F::Output: Send + 'static { ... }
    fn handle_supervision_event<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        _this: &'life1 Instance<Self>,
        _event: &'life2 ActorSupervisionEvent,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn handle_undeliverable_message<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        cx: &'life1 Instance<Self>,
        __arg2: Undeliverable<MessageEnvelope>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

An Actor is an independent, asynchronous thread of execution. Each actor instance has a mailbox, whose messages are delivered through the method [Actor::handle].

Actors communicate with each other by way of message passing. Actors are assumed to be deterministic: that is, the state of an actor is determined by the set (and order) of messages it receives.

Required Associated Types§

Source

type Params: Send + 'static

The type of initialization parameters accepted by this actor.

Required Methods§

Source

fn new<'async_trait>( params: Self::Params, ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Creates a new actor instance given its instantiation parameters.

Provided Methods§

Source

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, _this: &'life1 Instance<Self>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Initialize the actor, after the runtime has been fully initialized. Init thus provides a mechanism by which an actor can reliably and always receive some initial event that can be used to kick off further (potentially delayed) processing.

Source

fn spawn<'life0, 'async_trait>( cap: &'life0 (impl 'async_trait + CanSpawn), params: Self::Params, ) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Spawn a child actor, given a spawning capability (usually given by Instance). The spawned actor will be supervised by the parent (spawning) actor.

Source

fn spawn_detached<'async_trait>( params: Self::Params, ) -> Pin<Box<dyn Future<Output = Result<ActorHandle<Self>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Spawns this actor in a detached state, handling its messages in a background task. The returned handle is used to control the actor’s lifecycle and to interact with it.

Actors spawned through spawn_detached are not attached to a supervision hierarchy, and not managed by a Proc.

Source

fn spawn_server_task<F>(future: F) -> JoinHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

This method is used by the runtime to spawn the actor server. It can be used by actors that require customized runtime setups (e.g., dedicated actor threads), or want to use a custom tokio runtime.

Source

fn handle_supervision_event<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, _this: &'life1 Instance<Self>, _event: &'life2 ActorSupervisionEvent, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Handle actor supervision event. Return `Ok(true)`` if the event is handled here.

Source

fn handle_undeliverable_message<'life0, 'life1, 'async_trait>( &'life0 mut self, cx: &'life1 Instance<Self>, __arg2: Undeliverable<MessageEnvelope>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Default undeliverable message handling behavior.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Actor for ()

An actor that does nothing. It is used to represent “client only” actors, returned by Proc::instance.

Source§

type Params = ()

Source§

fn new<'async_trait>( params: Self::Params, ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Implementors§