#[cfg(feature = "stateful")]
macro_rules! impl_stateful_predicate_new_methods {
(BoxStatefulPredicate<$t:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@one $t, ('static), |$f| $w); };
(RcStatefulPredicate<$t:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@one $t, ('static), |$f| $w); };
(ArcStatefulPredicate<$t:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@one $t, (Send + 'static), |$f| $w); };
(BoxStatefulBiPredicate<$t:ident, $u:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@two $t, $u, ('static), |$f| $w); };
(RcStatefulBiPredicate<$t:ident, $u:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@two $t, $u, ('static), |$f| $w); };
(ArcStatefulBiPredicate<$t:ident, $u:ident>, |$f:ident| $w:expr) => { $crate::predicates::macros::impl_stateful_predicate_new_methods!(@two $t, $u, (Send + 'static), |$f| $w); };
(@one $t:ident, ($($b:tt)+), |$f:ident| $w:expr) => { crate::macros::impl_common_new_methods!(semantic_mut (StatefulPredicate<$t> + $($b)+), |source| move |value: &$t| source.test(value), |$f| $w, "predicate"); };
(@two $t:ident, $u:ident, ($($b:tt)+), |$f:ident| $w:expr) => { crate::macros::impl_common_new_methods!(semantic_mut (StatefulBiPredicate<$t, $u> + $($b)+), |source| move |first: &$t, second: &$u| source.test(first, second), |$f| $w, "bi-predicate"); };
}
macro_rules! impl_predicate_common_methods {
(
$struct_name:ident < $t:ident >,
semantic ($($semantic_bounds:tt)+),
|$source:ident| $adapter_expr:expr,
|$f:ident| $wrapper_expr:expr
) => {
crate::macros::impl_common_new_methods!(
semantic ($($semantic_bounds)+),
|$source| $adapter_expr,
|$f| $wrapper_expr,
"predicate"
);
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `true`.")]
#[inline]
pub fn always_true() -> Self {
Self::new_with_name(ALWAYS_TRUE_NAME, |_: &$t| true)
}
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `false`.")]
#[inline]
pub fn always_false() -> Self {
Self::new_with_name(ALWAYS_FALSE_NAME, |_: &$t| false)
}
crate::macros::impl_common_name_methods!("predicate");
};
(
$struct_name:ident < $t:ident, $u:ident >,
semantic ($($semantic_bounds:tt)+),
|$source:ident| $adapter_expr:expr,
|$f:ident| $wrapper_expr:expr
) => {
crate::macros::impl_common_new_methods!(
semantic ($($semantic_bounds)+),
|$source| $adapter_expr,
|$f| $wrapper_expr,
"bi-predicate"
);
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `true`.")]
#[inline]
pub fn always_true() -> Self {
Self::new_with_name(ALWAYS_TRUE_NAME, |_: &$t, _: &$u| true)
}
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `false`.")]
#[inline]
pub fn always_false() -> Self {
Self::new_with_name(ALWAYS_FALSE_NAME, |_: &$t, _: &$u| false)
}
crate::macros::impl_common_name_methods!("bi-predicate");
};
(
$struct_name:ident < $t:ident >,
($($fn_trait_with_bounds:tt)+),
|$f:ident| $wrapper_expr:expr
) => {
$crate::predicates::macros::impl_stateful_predicate_new_methods!($struct_name<$t>, |$f| $wrapper_expr);
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `true`.")]
#[inline]
pub fn always_true() -> Self {
Self::new_with_name(ALWAYS_TRUE_NAME, |_: &$t| true)
}
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `false`.")]
#[inline]
pub fn always_false() -> Self {
Self::new_with_name(ALWAYS_FALSE_NAME, |_: &$t| false)
}
crate::macros::impl_common_name_methods!("predicate");
};
(
$struct_name:ident < $t:ident, $u:ident >,
($($fn_trait_with_bounds:tt)+),
|$f:ident| $wrapper_expr:expr
) => {
$crate::predicates::macros::impl_stateful_predicate_new_methods!($struct_name<$t, $u>, |$f| $wrapper_expr);
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `true`.")]
#[inline]
pub fn always_true() -> Self {
Self::new_with_name(ALWAYS_TRUE_NAME, |_: &$t, _: &$u| true)
}
#[doc = concat!("A new `", stringify!($struct_name), "` that always returns `false`.")]
#[inline]
pub fn always_false() -> Self {
Self::new_with_name(ALWAYS_FALSE_NAME, |_: &$t, _: &$u| false)
}
crate::macros::impl_common_name_methods!("bi-predicate");
};
}
pub(crate) use impl_predicate_common_methods;
#[cfg(feature = "stateful")]
pub(crate) use impl_stateful_predicate_new_methods;