act_rs 0.5.0

Act.rs is a minimal actor framework.
Documentation

use std::panic::UnwindSafe;

#[cfg(feature = "async-trait")]
use async_trait::async_trait;

//Disabled

//use async_trait::async_trait;

///
/// The trait used for standard thread and blocking thread based actors.
/// 
/// The returned boolean values from the pre_run and run method implementations should indicate whether or not actor execution should proceed.
/// 
pub trait ActorState : Sized
{

    fn pre_run(&mut self) -> bool
    {

        true

    }

    fn run(&mut self) -> bool;

    fn post_run(self)
    {
    }

}

///
/// The trait used for async oriented actors.
/// 
/// The returned boolean values from the pre_run_async and run_async method implementations should indicate whether or not actor execution should proceed.
///
#[cfg(feature = "async-trait")]
#[async_trait]
pub trait ActorStateAsync : Sized
{

    async fn pre_run_async(&mut self) -> bool
    {

        true

    }

    async fn run_async(&mut self) -> bool;

    async fn post_run_async(self)
    {
    }

}

#[cfg(feature = "async-trait")]
#[async_trait]
pub trait ActorStateUnwindSafeAsync : ActorStateAsync + UnwindSafe + Sized
{
}