#![no_std]
use core::ops::ControlFlow;
pub use internal_iterator::*;
pub trait InternalIteratorRec:
InternalIterator<Item = <Self as InternalIteratorRec>::Item>
{
type Item;
fn try_for_each_rec<R, F>(self, f: &mut F) -> ControlFlow<R>
where
F: FnMut(<Self as InternalIteratorRec>::Item) -> ControlFlow<R>;
}
#[macro_export]
macro_rules! internal_iterator_rec_guts {
() => {
type Item = <Self as InternalIteratorRec>::Item;
fn try_for_each<R, F>(self, f: F) -> ::core::ops::ControlFlow<R>
where
F: FnMut(Self::Item) -> ::core::ops::ControlFlow<R>,
{
self.try_for_each_rec(&mut { f })
}
};
}
#[macro_export]
#[rustfmt::skip]
macro_rules! adhoc_internal_iterator_rec {(
$lt:lifetime,
$value:expr,
|$($this:ident)+ : $T:ty, $yield:ident $(,)?| -> $ItemTy:ty
$body:block
$(,)?
) => ({
struct AdhocInternalIteratorRec<$lt>($T);
impl<$lt> $crate::InternalIteratorRec for AdhocInternalIteratorRec<$lt> {
type Item = $ItemTy;
fn try_for_each_rec<R, F>(self, $yield: &mut F) -> ::core::ops::ControlFlow<R>
where
F: FnMut(<Self as $crate::InternalIteratorRec>::Item) -> ::core::ops::ControlFlow<R>,
{
let Self($($this)+) = self;
$body
::core::ops::ControlFlow::Continue(())
}
}
impl $crate::InternalIterator for AdhocInternalIteratorRec<'_> {
$crate::internal_iterator_rec_guts!();
}
AdhocInternalIteratorRec($value)
})
}