use std::marker::PhantomData;
#[allow(unused_imports)]
use crate::events_impl::{
core::{Bhv, Status},
decor::*,
events::{Event, EventExt, EventType, EventTypeExt},
};
pub trait BhvExt: Bhv + Sized {
#[inline]
fn inv(self) -> Inv<Self> {
Inv(self)
}
#[inline]
fn pass(self) -> Pass<Self> {
Pass(self)
}
#[inline]
fn fail(self) -> Fail<Self> {
Fail(self)
}
#[inline]
fn repeat(self, count: u32) -> Repeat<Self> {
Repeat {
bhv: self,
count,
current: 0,
}
}
#[inline]
fn repeat_until_pass(self) -> RepeatUntilPass<Self> {
RepeatUntilPass(self)
}
#[inline]
fn repeat_until_fail(self) -> RepeatUntilFail<Self> {
RepeatUntilFail(self)
}
#[inline]
fn wait_for<E: EventType>(self) -> WaitFor<Self, E> {
WaitFor {
bhv: self,
kind: E::static_event_type(),
_tag: PhantomData,
}
}
fn execute<'a>(
mut self,
events: impl IntoIterator<Item=&'a dyn Event>,
ctx: &mut Self::Context,
) {
for event in events {
if !self.should_react_to(event.event_type()) {
break;
} else {
match self.react(event, ctx) {
Status::Running => continue,
_ => return,
}
}
}
}
}
impl<B> BhvExt for B where B: Bhv + Sized {}