macro_rules! impl_shared_consumer_methods {
(@and_then Consumer, $struct_name:ident, $first:expr, $after:expr, $t:ident) => {{
let first = $first;
let after = $after;
$struct_name::new(move |t: &$t| {
first.accept(t);
after.accept(t);
})
}};
(@and_then StatefulConsumer, $struct_name:ident, $first:expr, $after:expr, $t:ident) => {{
let mut first = $first;
let mut after = $after;
$struct_name::new(move |t: &$t| {
first.accept(t);
after.accept(t);
})
}};
(@and_then_bi BiConsumer, $struct_name:ident, $first:expr, $after:expr, $t:ident, $u:ident) => {{
let first = $first;
let after = $after;
$struct_name::new(move |t: &$t, u: &$u| {
first.accept(t, u);
after.accept(t, u);
})
}};
(@and_then_bi StatefulBiConsumer, $struct_name:ident, $first:expr, $after:expr, $t:ident, $u:ident) => {{
let mut first = $first;
let mut after = $after;
$struct_name::new(move |t: &$t, u: &$u| {
first.accept(t, u);
after.accept(t, u);
})
}};
(
$struct_name:ident < $t:ident >,
$return_type:ident,
$predicate_type:ident,
$consumer_trait:ident,
predicate_bounds = ($($predicate_bounds:tt)+),
chained_bounds = ($($chained_bounds:tt)+)
) => {
#[inline]
pub fn when<P>(&self, predicate: P) -> $return_type<$t>
where
$t: 'static,
P: Predicate<$t> + $($predicate_bounds)+,
{
$return_type {
consumer: self.clone(),
predicate: $crate::$predicate_type::new(predicate),
}
}
#[inline]
pub fn and_then<C>(&self, after: C) -> $struct_name<$t>
where
$t: 'static,
C: $consumer_trait<$t> + $($chained_bounds)+,
{
impl_shared_consumer_methods!(@and_then $consumer_trait, $struct_name, self.clone(), after, $t)
}
};
(
$struct_name:ident < $t:ident, $u:ident >,
$return_type:ident,
$predicate_type:ident,
$consumer_trait:ident,
predicate_bounds = ($($predicate_bounds:tt)+),
chained_bounds = ($($chained_bounds:tt)+)
) => {
#[inline]
pub fn when<P>(&self, predicate: P) -> $return_type<$t, $u>
where
$t: 'static,
$u: 'static,
P: BiPredicate<$t, $u> + $($predicate_bounds)+,
{
$return_type {
consumer: self.clone(),
predicate: $crate::$predicate_type::new(predicate),
}
}
#[inline]
pub fn and_then<C>(&self, after: C) -> $struct_name<$t, $u>
where
$t: 'static,
$u: 'static,
C: $consumer_trait<$t, $u> + $($chained_bounds)+,
{
impl_shared_consumer_methods!(@and_then_bi $consumer_trait, $struct_name, self.clone(), after, $t, $u)
}
};
}
pub(crate) use impl_shared_consumer_methods;