3 use crate::async_iter::AsyncIterator;
4 use crate::task::{Context, Poll};
6 /// An async iterator that was created from iterator.
8 /// This async iterator is created by the [`from_iter`] function.
9 /// See it documentation for more.
11 /// [`from_iter`]: fn.from_iter.html
12 #[unstable(feature = "async_iter_from_iter", issue = "81798")]
13 #[derive(Clone, Debug)]
14 pub struct FromIter<I> {
18 #[unstable(feature = "async_iter_from_iter", issue = "81798")]
19 impl<I> Unpin for FromIter<I> {}
21 /// Converts an iterator into an async iterator.
22 #[unstable(feature = "async_iter_from_iter", issue = "81798")]
23 pub fn from_iter<I: IntoIterator>(iter: I) -> FromIter<I::IntoIter> {
24 FromIter { iter: iter.into_iter() }
27 #[unstable(feature = "async_iter_from_iter", issue = "81798")]
28 impl<I: Iterator> AsyncIterator for FromIter<I> {
31 fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
32 Poll::Ready(self.iter.next())
35 fn size_hint(&self) -> (usize, Option<usize>) {