Function lending_iterator::repeat_mut
source · pub fn repeat_mut<State>(state: State) -> RepeatMut<State> ⓘ
Expand description
Returns an infinite impl LendingIterator
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
-
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"], );