Skip to main content

Actor

Trait Actor 

Source
pub trait Actor:
    Send
    + Sync
    + 'static {
    type Message: Send + 'static;
    type State: Send + 'static;
    type Initialize: Send + 'static;

    // Required methods
    fn initialize<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        handle: &'life1 ActorHandle<Self::Message>,
        tags: &'life2 Tags,
        initialize: Self::Initialize,
    ) -> Pin<Box<dyn Future<Output = Result<Self::State, ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn handle<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        handle: &'life1 ActorHandle<Self::Message>,
        message: Self::Message,
        state: &'life2 mut Self::State,
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn tags(&self, tags: Tags) -> Result<Tags, ActorError> { ... }
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
        _state: Self::State,
    ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn spawner(
        tags: Tags,
        actor: Self,
    ) -> Result<ActorSpawner<Self>, ActorError>
       where Self: Send + Sync + Sized + 'static { ... }
    fn spawn(
        tags: Tags,
        actor: Self,
        initialize: Self::Initialize,
    ) -> Result<ActorInstance<Self>, ActorError>
       where Self: Send + Sync + Sized + 'static { ... }
    fn spawn_with(
        spawner: TaskSpawner,
        tags: Tags,
        actor: Self,
        initialize: Self::Initialize,
    ) -> Result<ActorInstance<Self>, ActorError>
       where Self: Send + Sync + Sized + 'static { ... }
}
Expand description

Simple actor model implementation. Accepts messages which will be applied to the actor state. Actor state is different to the actual actor instance in order to allow initialization of it within the actor context.

Required Associated Types§

Source

type Message: Send + 'static

Source

type State: Send + 'static

Source

type Initialize: Send + 'static

Required Methods§

Source

fn initialize<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ActorHandle<Self::Message>, tags: &'life2 Tags, initialize: Self::Initialize, ) -> Pin<Box<dyn Future<Output = Result<Self::State, ActorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn handle<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, handle: &'life1 ActorHandle<Self::Message>, message: Self::Message, state: &'life2 mut Self::State, ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Provided Methods§

Source

fn tags(&self, tags: Tags) -> Result<Tags, ActorError>

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, _state: Self::State, ) -> Pin<Box<dyn Future<Output = Result<(), ActorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Shutdown the actor. This is not cancelable. After this call no more message will be received. Will not be executed if actor panics.

Source

fn spawner(tags: Tags, actor: Self) -> Result<ActorSpawner<Self>, ActorError>
where Self: Send + Sync + Sized + 'static,

Source

fn spawn( tags: Tags, actor: Self, initialize: Self::Initialize, ) -> Result<ActorInstance<Self>, ActorError>
where Self: Send + Sync + Sized + 'static,

Spawn actor.

Source

fn spawn_with( spawner: TaskSpawner, tags: Tags, actor: Self, initialize: Self::Initialize, ) -> Result<ActorInstance<Self>, ActorError>
where Self: Send + Sync + Sized + 'static,

Spawn actor using a task spawner.

Implementors§