lending-iterator 0.1.7

Fully general lending iterators in stable rust: windows_mut!
Documentation
/// The <code>impl [LendingIterator]</code> returned by
/// [`.map()`][LendingIterator::map()].
pub
struct Map<I, F, NewItemType>
where
    I : LendingIterator,
    NewItemType : HKT,
    for<'any>
        F : FnMut(
            [&'any I; 0],
            Item<'any, I>,
        ) -> A!(NewItemType<'any>)
    ,
{
    pub(in crate)
    iter: I,

    pub(in crate)
    map: F,

    pub(in crate)
    _phantom_ty: ::core::marker::PhantomData<fn() -> NewItemType>,
}

#[gat]
impl<I, NewItemType, F> LendingIterator
    for Map<I, F, NewItemType>
where
    I : LendingIterator,
    NewItemType : HKT,
    for<'any>
        F : FnMut(
            [&'any I; 0],
            Item<'any, I>,
        ) -> A!(NewItemType<'any>)
    ,
{
    type Item<'next>
    where
        Self : 'next,
    =
        A!(NewItemType<'next>)
    ;

    fn next (
        self: &'_ mut Map<I, F, NewItemType>,
    ) -> Option<A!(NewItemType<'_>)>
    {
        self.iter.next().map(|item| (self.map)([], item))
    }
}

/// The <code>impl [LendingIterator]</code> returned by
/// [`.map_into_iter()`][LendingIterator::map_into_iter()].
pub
struct MapIntoIter<I, F>
(
    pub(in crate) I,
    pub(in crate) F,
)
where
    I : LendingIterator,
    for<'any>
        F : crate::utils::FnMut<Item<'any, I>>
    ,
;

impl<I, F, R>
    Iterator
for
    MapIntoIter<I, F>
where
    I : LendingIterator,
    F : FnMut(Item<'_, I>) -> R,
{
    type Item = R;

    fn next (
        self: &'_ mut MapIntoIter<I, F>,
    ) -> Option<R>
    {
        self.0.next().map(&mut self.1)
    }
}