use std::marker::PhantomData;
#[allow(unused_imports)]
use crate::events_impl::{
core::{Bhv, Status},
events::{Event, UnitEventPump},
};
#[derive(Clone)]
pub struct Action<A, C>(A, PhantomData<C>)
where
A: FnMut(&mut C);
#[derive(Clone)]
pub struct Cond<P, C>(P, PhantomData<C>)
where
P: Fn(&C) -> bool;
#[derive(Clone)]
pub struct AsyncAction<A, C>(A, PhantomData<C>)
where A: FnMut(&mut C) -> Status;
impl<A, C> Bhv for Action<A, C>
where A: FnMut(&mut C) {
type Context = C;
#[inline]
fn react(&mut self, _event: &dyn Event, ctx: &mut Self::Context) -> Status {
self.0(ctx);
Status::Success
}
}
impl<P, C> Bhv for Cond<P, C>
where P: Fn(&C) -> bool {
type Context = C;
#[inline]
fn react(&mut self, _event: &dyn Event, ctx: &mut Self::Context) -> Status {
if self.0(ctx) {
Status::Success
} else {
Status::Failure
}
}
}
impl<A, C> Bhv for AsyncAction<A, C>
where A: FnMut(&mut C) -> Status {
type Context = C;
#[inline]
fn react(&mut self, _event: &dyn Event, ctx: &mut Self::Context) -> Status {
self.0(ctx)
}
}
#[inline]
pub fn action<A, C>(a: A) -> Action<A, C>
where A: FnMut(&mut C) { Action(a, PhantomData) }
#[inline]
pub fn cond<P, C>(p: P) -> Cond<P, C>
where P: Fn(&C) -> bool { Cond(p, PhantomData) }
#[inline]
pub fn async_action<A, C>(a: A) -> AsyncAction<A, C>
where A: FnMut(&mut C) -> Status { AsyncAction(a, PhantomData) }