[][src]Trait meio::Actor

pub trait Actor: Sized + Send + 'static {
    type Interface: Interface<Self>;
    fn generic_name() -> &'static str;

#[must_use]    fn initialize<'life0, 'async_trait>(
        &'life0 mut self,
        _address: Address<Self>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] fn routine<'life0, 'async_trait>(
        &'life0 mut self,
        ctx: Context<Self>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] fn terminate<'life0, 'async_trait>(
        &'life0 mut self
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
, { ... } }

The main trait. Your structs have to implement it to be compatible with Runtime and Address system.

Associated Types

type Interface: Interface<Self>

Actor use this Interface to wrap Address and provide a convenient way to interact with Actor.

Loading content...

Required methods

fn generic_name() -> &'static str

Return a generic name of an Actor. The instance haven't change the value during runtime.

Loading content...

Provided methods

#[must_use]fn initialize<'life0, 'async_trait>(
    &'life0 mut self,
    _address: Address<Self>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Called when actor teminating.

#[must_use]fn routine<'life0, 'async_trait>(
    &'life0 mut self,
    ctx: Context<Self>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

The single routine of your Actor. Just implement this method. If you will override this method you should implement processing for incoming Envelope messages (if you want to process messages):

This example is not tested
async fn routine(&mut self, mut ctx: Context<Self>) -> Result<(), Error> {
    while let Some(mut envelope) = ctx.rx.next().await {
        envelope.handler.handle(self).await?;
    }
    Ok(())
}

#[must_use]fn terminate<'life0, 'async_trait>(
    &'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Called when actor teminating.

Loading content...

Implementors

Loading content...