use rotor::{Scope, Machine, Response, EventSet, Void};
pub struct Uniform<T: Action>(pub T);
pub trait Action: Sized {
type Context;
type Seed;
fn create(seed: Self::Seed, scope: &mut Scope<Self::Context>)
-> Response<Self, Void>;
fn action(self, scope: &mut Scope<Self::Context>)
-> Response<Self, Self::Seed>;
}
impl<T: Action> Machine for Uniform<T> {
type Context = T::Context;
type Seed = T::Seed;
fn create(seed: Self::Seed, scope: &mut Scope<Self::Context>)
-> Response<Self, Void>
{
Action::create(seed, scope).wrap(Uniform)
}
fn ready(self, _events: EventSet, scope: &mut Scope<Self::Context>)
-> Response<Self, Self::Seed>
{
self.0.action(scope).wrap(Uniform)
}
fn spawned(self, scope: &mut Scope<Self::Context>)
-> Response<Self, Self::Seed>
{
self.0.action(scope).wrap(Uniform)
}
fn timeout(self, scope: &mut Scope<Self::Context>)
-> Response<Self, Self::Seed>
{
self.0.action(scope).wrap(Uniform)
}
fn wakeup(self, scope: &mut Scope<Self::Context>)
-> Response<Self, Self::Seed>
{
self.0.action(scope).wrap(Uniform)
}
}