[][src]Trait act_zero::Actor

pub trait Actor: Send + 'static {
#[must_use]    pub fn started<'life0, 'async_trait>(
        &'life0 mut self,
        _addr: Addr<Self>
    ) -> Pin<Box<dyn Future<Output = ActorResult<()>> + Send + 'async_trait>>
    where
        Self: Sized,
        'life0: 'async_trait,
        Self: 'async_trait
, { ... }
#[must_use] pub fn error<'life0, 'async_trait>(
        &'life0 mut self,
        error: ActorError
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
, { ... } }

Trait implemented by all actors. This trait is defined using the #[async_trait] attribute:

#[async_trait]
pub trait Actor: Send + 'static {
    /// Called automatically when an actor is started. Actors can use this
    /// to store their own address for future use.
    async fn started(&mut self, _addr: Addr<Self>) -> ActorResult<()>
    where
        Self: Sized,
    {
        Ok(())
    }

    /// Called when any actor method returns an error. If this method
    /// returns `true`, the actor will stop.
    /// The default implementation logs the error using the `log` crate
    /// and then stops the actor.
    async fn error(&mut self, error: ActorError) -> bool {
        error!("{}", error);
        true
    }
}

In order to use a trait object with the actor system, such as with Addr<dyn Trait>, the trait must extend this Actor trait.

Provided methods

#[must_use]pub fn started<'life0, 'async_trait>(
    &'life0 mut self,
    _addr: Addr<Self>
) -> Pin<Box<dyn Future<Output = ActorResult<()>> + Send + 'async_trait>> where
    Self: Sized,
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

Called automatically when an actor is started. Actors can use this to store their own address for future use.

#[must_use]pub fn error<'life0, 'async_trait>(
    &'life0 mut self,
    error: ActorError
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

Called when any actor method returns an error. If this method returns true, the actor will stop. The default implementation logs the error using the log crate and then stops the actor.

Loading content...

Implementors

Loading content...