dyner icon indicating copy to clipboard operation
dyner copied to clipboard

DynAsyncIter needs a lifetime bound

Open nikomatsakis opened this issue 4 years ago • 0 comments

@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);
}

nikomatsakis avatar Oct 14 '21 22:10 nikomatsakis