1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/// I wish we could just use this…
#[cfg(any())]
pub
fn repeat_mut<State> (state: State)
-> impl for<'any> LendingIteratorඞItem<'any, T = &'any mut State>
+ LendingIterator
{
from_fn::<HKT!(&mut State), _, _>(state, |it| Some(it))
}
/// Returns an infinite <code>impl [LendingIterator]</code> which lends
/// `&'next mut State` items.
///
/// Useful as an entry-point for the other combinators and adapters.
///
/// It is also conceptually interesting since it features one of the simplest
/// `.next()` implementations, as an "identity" function: `|self| Some(self)`.
///
/// And yet, such a `next()` implementation would have been impossible to
/// feature using an [`Iterator`], since the returned item would not be allowed
/// to keep borrowing from `*self`.
///
/// ## Example
///
/** - ```rust
use ::lending_iterator::prelude::*;
let iter =
lending_iterator::repeat_mut("Globby")
.take(7)
.map_into_iter(|&mut globby| globby)
;
assert_eq!(
iter.collect::<Vec<_>>(),
["Globby", "Globby", "Globby", "Globby", "Globby", "Globby", "Globby"],
);
``` */
pub
fn repeat_mut<State> (state: State)
-> RepeatMut<State>
{
RepeatMut(state)
}
/// The <code>impl [LendingIterator]</code> returned by [`repeat_mut()`].
pub
struct RepeatMut<State>(
State,
);
#[gat]
impl<State>
LendingIterator
for
RepeatMut<State>
{
type Item<'next>
where
Self : 'next,
=
&'next mut State
;
fn next (
self: &'_ mut RepeatMut<State>,
) -> Option<&'_ mut State>
{
Some(&mut self.0)
}
}