dyner
dyner copied to clipboard
DynAsyncIter needs a lifetime bound
@dtolnay pointed out that we are losing track of some lifetimes in the current example; we need to include a lifetime bound, most likely:
impl<'a, T: Copy> AsyncIter for std::slice::Iter<'a, T> {
type Item = T;
type Next<'me> where 'a: 'me = impl Future<Output = Option<Self::Item>> + 'me;
fn next(&mut self) -> Self::Next<'_> {
async move { Iterator::next(self).copied() }
}
}
let string = ".".repeat(20);
let mut boxed_range = async_iter::DynAsyncIter::new(string.as_bytes().iter());
drop(string);
while let Some(v) = boxed_range.next().await {
println!("v={}", v);
}