seal_rs 0.3.2

Set of classic asynchronous primitives (Actors, Executors, Futures / Promises)
Documentation
use crate::actors::actor::Actor;
use crate::actors::actor_context::ActorContext;
use crate::actors::props::Props;
use crate::exps::boo::Boo;
use std::sync::{Arc, Mutex};
use std::any::Any;


pub struct Ping {
    pub v: u32,
    pub xt: String
}

pub struct Zoom {

}



pub struct Foo {
 pub some_data: u32
}

impl Foo {
    pub fn new() -> Foo {
        Foo {
            some_data: 0
        }
    }
}

impl Actor for Foo {
    fn pre_start(self: &mut Self, ctx: ActorContext) {
        //println!("foo preStart");
        //println!("self = {}", ctx.self_);
        //println!("sender = {}", ctx.sender);
        ctx.system.lock().unwrap().actor_of(Props::new(tsafe!(Boo::new())), Some("boo"));

    }

    fn post_stop(self: &mut Self, _ctx: ActorContext) {
        println!("foo postStop");
    }

    fn receive(self: &mut Self, msg: &Box<Any + Send>, ctx: ActorContext) -> bool {
        if let Some(Zoom {}) = msg.downcast_ref::<Zoom>() {
            println!("it was Zoom!");
        } else if let Some(Ping { v, xt }) = msg.downcast_ref::<Ping>() {
            println!("it was Ping! v = {}, xt={}", v, xt);
            //ctx.system.lock().unwrap().stop(&ctx.self_);
            self.some_data = 100;
        } else {
            return false
        }

        true
    }
}