Actor

Trait Actor 

Source
pub trait Actor: Addr {
    type Context;

    // Required methods
    fn ctx<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = RwLockReadGuard<'_, Self::Context>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn ctx_mut<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'_, Self::Context>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn start<Id: Into<ActorId> + Send>(
        id: Id,
        ctx: Self::Context,
    ) -> Result<StrongAddr<Self>, ActorStartError>;
}
Expand description

Actor trait that all generic (non-specialized) actors must implement.

§Usage

Implementation is generated by the [vin::actor] proc macro.

§Behind the scenes

The way actors work in [vin] is that they live in their own tokio task, polling messages sent and starting handler tasks for each message received. Shutdown is also synchronized and actors will be given time to gracefully shutdown before being forcibly closed.

Required Associated Types§

Required Methods§

Source

fn ctx<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = RwLockReadGuard<'_, Self::Context>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a read lock to the underlying actor context.

Source

fn ctx_mut<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = RwLockWriteGuard<'_, Self::Context>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a write lock to the underlying actor context.

Source

fn start<Id: Into<ActorId> + Send>( id: Id, ctx: Self::Context, ) -> Result<StrongAddr<Self>, ActorStartError>

Creates and starts an actor with the given id (if available) and context.

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.

Implementors§