bottle 0.1.0

Actor model framework for Rust.
pub use crate::remote::Receiver;

/// Thread query
pub trait Query: Send {
    fn process(&mut self);

    fn receiver(&self) -> Option<Receiver> {
        None
    }
}

pub struct Callback<F: FnOnce() -> () + Send> {
    callback: Option<F>
}

impl<F: FnOnce() -> () + Send> Callback<F> {
    pub fn new(f: F) -> Callback<F> {
        Callback {
            callback: Some(f)
        }
    }
}

impl<F: FnOnce() -> () + Send> Query for Callback<F> {
    fn process(&mut self) {
        let mut callback = None;
        std::mem::swap(&mut self.callback, &mut callback);
        match callback {
            Some(f) => (f)(),
            None => ()
        }
    }
}