From aec10c000d83e9ea264a597c9176a46b24b7bec6 Mon Sep 17 00:00:00 2001 From: Skye Jensen Date: Fri, 5 Jun 2020 20:08:23 -0400 Subject: [PATCH] Clean up AsyncIter --- src/async_iter.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/async_iter.rs b/src/async_iter.rs index cd85f32..cd11cc8 100644 --- a/src/async_iter.rs +++ b/src/async_iter.rs @@ -1,24 +1,19 @@ use async_trait::async_trait; -use futures::stream::BoxStream; -use futures::{stream }; +use futures::stream::{self, BoxStream}; #[async_trait] -trait AsyncIter { - type Item: Sized; +pub trait AsyncIter { + type Item; async fn next(&mut self) -> Option; - fn into_stream(self) -> BoxStream<'static, Self::Item> + fn into_stream<'a>(self) -> BoxStream<'a, Self::Item> where - Self: Sized + Send + 'static, + Self: Sized + Send + 'a, { - async fn helper(mut iter: I) -> Option<(I::Item, I)> - where - I: AsyncIter, - { + Box::pin(stream::unfold(self, |mut iter| async { let value = iter.next().await?; Some((value, iter)) - } - Box::pin(stream::unfold(self, helper)) + })) } } @@ -26,8 +21,7 @@ trait AsyncIter { #[cfg(test)] mod test { use super::*; - use futures::StreamExt; - use futures::executor; + use futures::{executor, StreamExt}; struct Numbers(usize); impl Numbers {